Migrate tests to AssertJ
Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj There is still a lot of work to do when complex and composite matchers are used. * Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor of `awaitility` * Remove Hamcrest from dependencies and disable JUnit & Hamcrest static imports to encourage to use only AssertJ * Migrate JUnit assumptions in rules to AssertJ's assumptions * Deprecate some custom matchers in favor of existing in Hamcrest after upgrading the last to version `2.1` * Replace `ExpectedException` rules with `assertThatThrownBy()` * Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.security.channel;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
@@ -98,7 +95,7 @@ public class ChannelAdapterSecurityIntegrationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
securedChannelAdapter.send(new GenericMessage<String>("test"));
|
||||
securedChannelAdapter2.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 2, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,17 +103,17 @@ public class ChannelAdapterSecurityIntegrationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
this.queueChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
this.queueChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> errorMessage = this.errorChannel.receive(10000);
|
||||
assertNotNull(errorMessage);
|
||||
assertThat(errorMessage).isNotNull();
|
||||
Object payload = errorMessage.getPayload();
|
||||
assertThat(payload, instanceOf(MessageHandlingException.class));
|
||||
assertThat(((MessageHandlingException) payload).getCause(),
|
||||
instanceOf(AuthenticationCredentialsNotFoundException.class));
|
||||
assertThat(payload).isInstanceOf(MessageHandlingException.class);
|
||||
assertThat(((MessageHandlingException) payload).getCause())
|
||||
.isInstanceOf(AuthenticationCredentialsNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
@@ -140,20 +137,20 @@ public class ChannelAdapterSecurityIntegrationTests {
|
||||
public void testUnsecuredAsAdmin() {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN");
|
||||
unsecuredChannelAdapter.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsecuredAsUser() {
|
||||
login("bob", "bobspassword", "ROLE_USER");
|
||||
unsecuredChannelAdapter.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsecuredWithoutAuthenticating() {
|
||||
unsecuredChannelAdapter.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.security.config;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -145,7 +142,7 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
securedChannel.send(new GenericMessage<String>("test"));
|
||||
securedChannel2.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 2, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
@@ -169,20 +166,20 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
public void testUnsecuredAsAdmin() {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN");
|
||||
unsecuredChannel.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsecuredAsUser() {
|
||||
login("bob", "bobspassword", "ROLE_USER");
|
||||
unsecuredChannel.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsecuredWithoutAuthenticating() {
|
||||
unsecuredChannel.send(new GenericMessage<String>("test"));
|
||||
assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size());
|
||||
assertThat(testConsumer.sentMessages.size()).as("Wrong size of message list in target").isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,17 +187,17 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
this.queueChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
this.queueChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> errorMessage = this.errorChannel.receive(10000);
|
||||
assertNotNull(errorMessage);
|
||||
assertThat(errorMessage).isNotNull();
|
||||
Object payload = errorMessage.getPayload();
|
||||
assertThat(payload, instanceOf(MessageHandlingException.class));
|
||||
assertThat(((MessageHandlingException) payload).getCause(),
|
||||
instanceOf(AuthenticationCredentialsNotFoundException.class));
|
||||
assertThat(payload).isInstanceOf(MessageHandlingException.class);
|
||||
assertThat(((MessageHandlingException) payload).getCause())
|
||||
.isInstanceOf(AuthenticationCredentialsNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,17 +205,17 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
this.executorChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
this.executorChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> errorMessage = this.errorChannel.receive(10000);
|
||||
assertNotNull(errorMessage);
|
||||
assertThat(errorMessage).isNotNull();
|
||||
Object payload = errorMessage.getPayload();
|
||||
assertThat(payload, instanceOf(MessageHandlingException.class));
|
||||
assertThat(((MessageHandlingException) payload).getCause(),
|
||||
instanceOf(AuthenticationCredentialsNotFoundException.class));
|
||||
assertThat(payload).isInstanceOf(MessageHandlingException.class);
|
||||
assertThat(((MessageHandlingException) payload).getCause())
|
||||
.isInstanceOf(AuthenticationCredentialsNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,28 +225,28 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
this.publishSubscribeChannel.send(new GenericMessage<String>("test"));
|
||||
|
||||
Message<?> receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(receive);
|
||||
assertEquals(0, headerAccessor.getSequenceNumber());
|
||||
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(0);
|
||||
|
||||
receive = this.securedChannelQueue2.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
headerAccessor = new IntegrationMessageHeaderAccessor(receive);
|
||||
assertEquals(0, headerAccessor.getSequenceNumber());
|
||||
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(0);
|
||||
|
||||
this.publishSubscribeChannel.setApplySequence(true);
|
||||
|
||||
this.publishSubscribeChannel.send(new GenericMessage<String>("test"));
|
||||
|
||||
receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
headerAccessor = new IntegrationMessageHeaderAccessor(receive);
|
||||
assertEquals(1, headerAccessor.getSequenceNumber());
|
||||
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(1);
|
||||
|
||||
receive = this.securedChannelQueue2.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
headerAccessor = new IntegrationMessageHeaderAccessor(receive);
|
||||
assertEquals(2, headerAccessor.getSequenceNumber());
|
||||
assertThat(headerAccessor.getSequenceNumber()).isEqualTo(2);
|
||||
|
||||
this.publishSubscribeChannel.setApplySequence(false);
|
||||
|
||||
@@ -257,11 +254,11 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
|
||||
this.publishSubscribeChannel.send(new GenericMessage<String>("test"));
|
||||
Message<?> errorMessage = this.errorChannel.receive(10000);
|
||||
assertNotNull(errorMessage);
|
||||
assertThat(errorMessage).isNotNull();
|
||||
Object payload = errorMessage.getPayload();
|
||||
assertThat(payload, instanceOf(MessageHandlingException.class));
|
||||
assertThat(((MessageHandlingException) payload).getCause(),
|
||||
instanceOf(AuthenticationCredentialsNotFoundException.class));
|
||||
assertThat(payload).isInstanceOf(MessageHandlingException.class);
|
||||
assertThat(((MessageHandlingException) payload).getCause())
|
||||
.isInstanceOf(AuthenticationCredentialsNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,14 +266,14 @@ public class ChannelSecurityInterceptorSecuredChannelAnnotationTests {
|
||||
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
|
||||
Future<String> future = this.testGateway.test("foo");
|
||||
Message<?> receive = this.securedChannelQueue.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
MessageChannel replyChannel = receive.getHeaders().get(MessageHeaders.REPLY_CHANNEL, MessageChannel.class);
|
||||
replyChannel.send(new GenericMessage<>("bar"));
|
||||
|
||||
String result = future.get(10, TimeUnit.SECONDS);
|
||||
assertNotNull(result);
|
||||
assertEquals("bar", result);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result).isEqualTo("bar");
|
||||
}
|
||||
|
||||
private void login(String username, String password, String... roles) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.security.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -53,31 +51,31 @@ public class DefaultConfigurationTests {
|
||||
@Test
|
||||
public void verifyErrorChannel() {
|
||||
Object errorChannel = context.getBean("errorChannel");
|
||||
assertNotNull(errorChannel);
|
||||
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
|
||||
assertThat(errorChannel).isNotNull();
|
||||
assertThat(errorChannel.getClass()).isEqualTo(PublishSubscribeChannel.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyNullChannel() {
|
||||
Object nullChannel = context.getBean("nullChannel");
|
||||
assertNotNull(nullChannel);
|
||||
assertEquals(NullChannel.class, nullChannel.getClass());
|
||||
assertThat(nullChannel).isNotNull();
|
||||
assertThat(nullChannel.getClass()).isEqualTo(NullChannel.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyTaskScheduler() {
|
||||
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
|
||||
assertThat(taskScheduler.getClass()).isEqualTo(ThreadPoolTaskScheduler.class);
|
||||
ErrorHandler errorHandler = TestUtils.getPropertyValue(taskScheduler, "errorHandler", ErrorHandler.class);
|
||||
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
|
||||
assertThat(errorHandler.getClass()).isEqualTo(MessagePublishingErrorHandler.class);
|
||||
MessageChannel defaultErrorChannel = TestUtils.getPropertyValue(errorHandler,
|
||||
"messagingTemplate.defaultDestination", MessageChannel.class);
|
||||
assertNull(defaultErrorChannel);
|
||||
assertThat(defaultErrorChannel).isNull();
|
||||
errorHandler.handleError(new Throwable());
|
||||
defaultErrorChannel = TestUtils.getPropertyValue(errorHandler, "messagingTemplate.defaultDestination",
|
||||
MessageChannel.class);
|
||||
assertNotNull(defaultErrorChannel);
|
||||
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
|
||||
assertThat(defaultErrorChannel).isNotNull();
|
||||
assertThat(defaultErrorChannel).isEqualTo(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.security.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -67,16 +65,17 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
|
||||
messageChannel.setBeanName(beanName);
|
||||
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory()
|
||||
.applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
|
||||
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
|
||||
assertThat(AopUtils.isAopProxy(proxy)).as("Channel was not proxied").isTrue();
|
||||
Advisor[] advisors = ((Advised) proxy).getAdvisors();
|
||||
assertEquals("Wrong number of interceptors", 1, advisors.length);
|
||||
assertThat(advisors.length).as("Wrong number of interceptors").isEqualTo(1);
|
||||
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
|
||||
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
|
||||
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
|
||||
assertThat(policy).as("Pattern '" + beanName + "' is not included in mappings").isNotNull();
|
||||
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
|
||||
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
|
||||
assertTrue("ROLE_ADMIN not found as send attribute", this.getRolesFromDefintion(sendDefinition).contains("ROLE_ADMIN"));
|
||||
assertTrue("Policy applies to receive", receiveDefinition.size() == 0);
|
||||
assertThat(this.getRolesFromDefintion(sendDefinition).contains("ROLE_ADMIN"))
|
||||
.as("ROLE_ADMIN not found as send attribute").isTrue();
|
||||
assertThat(receiveDefinition.size() == 0).as("Policy applies to receive").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,18 +84,18 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
|
||||
messageChannel.setBeanName(beanName);
|
||||
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory()
|
||||
.applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
|
||||
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
|
||||
assertThat(AopUtils.isAopProxy(proxy)).as("Channel was not proxied").isTrue();
|
||||
Advisor[] advisors = ((Advised) proxy).getAdvisors();
|
||||
assertEquals("Wrong number of interceptors", 1, advisors.length);
|
||||
assertThat(advisors.length).as("Wrong number of interceptors").isEqualTo(1);
|
||||
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
|
||||
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
|
||||
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
|
||||
assertThat(policy).as("Pattern '" + beanName + "' is not included in mappings").isNotNull();
|
||||
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
|
||||
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
|
||||
Collection<String> sendRoles = this.getRolesFromDefintion(sendDefinition);
|
||||
assertTrue("ROLE_ADMIN not found as send attribute", sendRoles.contains("ROLE_ADMIN"));
|
||||
assertTrue("ROLE_USER not found as send attribute", sendRoles.contains("ROLE_USER"));
|
||||
assertTrue("Policy applies to receive", receiveDefinition.size() == 0);
|
||||
assertThat(sendRoles.contains("ROLE_ADMIN")).as("ROLE_ADMIN not found as send attribute").isTrue();
|
||||
assertThat(sendRoles.contains("ROLE_USER")).as("ROLE_USER not found as send attribute").isTrue();
|
||||
assertThat(receiveDefinition.size() == 0).as("Policy applies to receive").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,17 +104,17 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
|
||||
messageChannel.setBeanName(beanName);
|
||||
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory()
|
||||
.applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
|
||||
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
|
||||
assertThat(AopUtils.isAopProxy(proxy)).as("Channel was not proxied").isTrue();
|
||||
Advisor[] advisors = ((Advised) proxy).getAdvisors();
|
||||
assertEquals("Wrong number of interceptors", 1, advisors.length);
|
||||
assertThat(advisors.length).as("Wrong number of interceptors").isEqualTo(1);
|
||||
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
|
||||
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
|
||||
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
|
||||
assertThat(policy).as("Pattern '" + beanName + "' is not included in mappings").isNotNull();
|
||||
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
|
||||
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
|
||||
Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
|
||||
assertTrue("ROLE_ADMIN not found as receive attribute", receiveRoles.contains("ROLE_ADMIN"));
|
||||
assertTrue("Policy applies to receive", sendDefinition.size() == 0);
|
||||
assertThat(receiveRoles.contains("ROLE_ADMIN")).as("ROLE_ADMIN not found as receive attribute").isTrue();
|
||||
assertThat(sendDefinition.size() == 0).as("Policy applies to receive").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,18 +123,18 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
|
||||
messageChannel.setBeanName(beanName);
|
||||
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory()
|
||||
.applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
|
||||
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
|
||||
assertThat(AopUtils.isAopProxy(proxy)).as("Channel was not proxied").isTrue();
|
||||
Advisor[] advisors = ((Advised) proxy).getAdvisors();
|
||||
assertEquals("Wrong number of interceptors", 1, advisors.length);
|
||||
assertThat(advisors.length).as("Wrong number of interceptors").isEqualTo(1);
|
||||
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
|
||||
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
|
||||
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
|
||||
assertThat(policy).as("Pattern '" + beanName + "' is not included in mappings").isNotNull();
|
||||
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
|
||||
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
|
||||
Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
|
||||
assertTrue("ROLE_ADMIN not found as receive attribute", receiveRoles.contains("ROLE_ADMIN"));
|
||||
assertTrue("ROLE_USER not found as receive attribute", receiveRoles.contains("ROLE_USER"));
|
||||
assertTrue("Policy applies to receive", sendDefinition.size() == 0);
|
||||
assertThat(receiveRoles.contains("ROLE_ADMIN")).as("ROLE_ADMIN not found as receive attribute").isTrue();
|
||||
assertThat(receiveRoles.contains("ROLE_USER")).as("ROLE_USER not found as receive attribute").isTrue();
|
||||
assertThat(sendDefinition.size() == 0).as("Policy applies to receive").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,20 +143,20 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
|
||||
messageChannel.setBeanName(beanName);
|
||||
MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory()
|
||||
.applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
|
||||
assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
|
||||
assertThat(AopUtils.isAopProxy(proxy)).as("Channel was not proxied").isTrue();
|
||||
Advisor[] advisors = ((Advised) proxy).getAdvisors();
|
||||
assertEquals("Wrong number of interceptors", 1, advisors.length);
|
||||
assertThat(advisors.length).as("Wrong number of interceptors").isEqualTo(1);
|
||||
ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
|
||||
ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
|
||||
assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
|
||||
assertThat(policy).as("Pattern '" + beanName + "' is not included in mappings").isNotNull();
|
||||
Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
|
||||
Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
|
||||
assertNotNull("Pattern does not apply to 'send'", sendDefinition);
|
||||
assertNotNull("Pattern does not apply to 'receive'", receiveDefinition);
|
||||
assertThat(sendDefinition).as("Pattern does not apply to 'send'").isNotNull();
|
||||
assertThat(receiveDefinition).as("Pattern does not apply to 'receive'").isNotNull();
|
||||
Collection<String> sendRoles = this.getRolesFromDefintion(sendDefinition);
|
||||
Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
|
||||
assertTrue("ROLE_ADMIN not found in send attributes", sendRoles.contains("ROLE_ADMIN"));
|
||||
assertTrue("ROLE_ADMIN not found in receive attributes", receiveRoles.contains("ROLE_ADMIN"));
|
||||
assertThat(sendRoles.contains("ROLE_ADMIN")).as("ROLE_ADMIN not found in send attributes").isTrue();
|
||||
assertThat(receiveRoles.contains("ROLE_ADMIN")).as("ROLE_ADMIN not found in receive attributes").isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user