|
17 | 17 | package org.springframework.integration.file.remote;
|
18 | 18 |
|
19 | 19 | import static org.assertj.core.api.Assertions.assertThat;
|
| 20 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
20 | 21 | import static org.assertj.core.api.Assertions.fail;
|
21 | 22 | import static org.mockito.ArgumentMatchers.any;
|
22 | 23 | import static org.mockito.ArgumentMatchers.anyString;
|
| 24 | +import static org.mockito.ArgumentMatchers.eq; |
23 | 25 | import static org.mockito.Mockito.mock;
|
24 | 26 | import static org.mockito.Mockito.never;
|
25 | 27 | import static org.mockito.Mockito.verify;
|
| 28 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
26 | 29 | import static org.mockito.Mockito.when;
|
27 | 30 |
|
28 | 31 | import java.io.ByteArrayInputStream;
|
29 | 32 | import java.io.File;
|
30 | 33 | import java.io.IOException;
|
31 | 34 | import java.io.InputStream;
|
32 | 35 |
|
| 36 | +import org.jgroups.util.UUID; |
33 | 37 | import org.junit.Before;
|
34 | 38 | import org.junit.Rule;
|
35 | 39 | import org.junit.Test;
|
36 | 40 | import org.junit.rules.TemporaryFolder;
|
37 |
| -import org.mockito.Mockito; |
38 | 41 |
|
39 | 42 | import org.springframework.beans.factory.BeanFactory;
|
40 | 43 | import org.springframework.expression.common.LiteralExpression;
|
41 | 44 | import org.springframework.integration.file.remote.session.Session;
|
42 | 45 | import org.springframework.integration.file.remote.session.SessionFactory;
|
43 | 46 | import org.springframework.integration.file.support.FileExistsMode;
|
| 47 | +import org.springframework.messaging.MessageDeliveryException; |
44 | 48 | import org.springframework.messaging.MessagingException;
|
45 | 49 | import org.springframework.messaging.support.GenericMessage;
|
46 | 50 |
|
@@ -125,9 +129,36 @@ public void testIgnoreNotExists() throws Exception {
|
125 | 129 | @Test
|
126 | 130 | public void testStream() throws IOException {
|
127 | 131 | ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
|
128 |
| - this.template.send(new GenericMessage<InputStream>(stream), |
| 132 | + this.template.send(new GenericMessage<>(stream), |
129 | 133 | FileExistsMode.IGNORE);
|
130 |
| - verify(this.session).write(Mockito.eq(stream), Mockito.any()); |
| 134 | + verify(this.session).write(eq(stream), any()); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void testString() throws IOException { |
| 139 | + this.template.send(new GenericMessage<>("foo"), FileExistsMode.IGNORE); |
| 140 | + verify(this.session).write(any(InputStream.class), any()); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + public void testBytes() throws IOException { |
| 145 | + this.template.send(new GenericMessage<>("foo".getBytes()), FileExistsMode.IGNORE); |
| 146 | + verify(this.session).write(any(InputStream.class), any()); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void testMissingFile() { |
| 151 | + this.template.send(new GenericMessage<>(new File(UUID.randomUUID().toString())), FileExistsMode.IGNORE); |
| 152 | + verifyNoMoreInteractions(this.session); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testInvalid() { |
| 157 | + assertThatThrownBy(() -> this.template |
| 158 | + .send(new GenericMessage<>(new Object()), FileExistsMode.IGNORE)) |
| 159 | + .isInstanceOf(MessageDeliveryException.class) |
| 160 | + .hasCauseInstanceOf(IllegalArgumentException.class) |
| 161 | + .hasMessageContaining("Unsupported payload type"); |
131 | 162 | }
|
132 | 163 |
|
133 | 164 | }
|
0 commit comments