coheigea commented on a change in pull request #688:
URL: https://github.com/apache/cxf/pull/688#discussion_r469078906
##########
File path: core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
##########
@@ -122,4 +133,204 @@ public void testCreateContentID() throws Exception {
assertNotEquals(AttachmentUtil.createContentID(null),
AttachmentUtil.createContentID(null));
}
+ private CachedOutputStream testSetStreamedAttachmentProperties(final
String property, final Object value)
+ throws IOException {
+ return testSetStreamedAttachmentProperties(property, value, new
CachedOutputStream());
+ }
+
+ private CachedOutputStream testSetStreamedAttachmentProperties(final
String property, final Object value,
+ final CachedOutputStream cos) throws IOException {
+ Message message = new MessageImpl();
+ message.put(property, value);
+ AttachmentUtil.setStreamedAttachmentProperties(message, cos);
+
+ return cos;
+ }
+
+ @Test
+ public void bigIntAsAttachmentMemoryThreshold() throws IOException {
+ BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
bigInteger)) {
+ assertEquals(bigInteger.longValue(), cos.getThreshold());
+ }
+ // Overflow long value
+ bigInteger = bigInteger.add(BigInteger.ONE);
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
bigInteger)) {
+ assertEquals(AttachmentDeserializer.THRESHOLD, cos.getThreshold());
+ }
+ }
+
+ @Test
+ public void longAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
Long.MAX_VALUE)) {
+ assertEquals(Long.MAX_VALUE, cos.getThreshold());
+ }
+ }
+
+ @Test
+ public void integerAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
Integer.MAX_VALUE)) {
+ assertEquals(Integer.MAX_VALUE, cos.getThreshold());
+ }
+ }
+
+ @Test
+ public void shortAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
Short.MAX_VALUE)) {
+ assertEquals(Short.MAX_VALUE, cos.getThreshold());
+ }
+ }
+
+ @Test
+ public void byteAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD,
Byte.MAX_VALUE)) {
+ assertEquals(Byte.MAX_VALUE, cos.getThreshold());
+ }
+ }
+
+ @Test
+ public void numberStringAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "12345")) {
+ assertEquals(12345, cos.getThreshold());
+ }
+ }
+
+ @Test(expected = IOException.class)
+ public void nonNumberStringAsAttachmentMemoryThreshold() throws
IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "test")) {
+ // Will throw exception
+ }
+ }
+
+ @Test(expected = IOException.class)
+ public void objectAsAttachmentMemoryThreshold() throws IOException {
+ try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+ AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, new
Object())) {
+ // Will throw exception
+ }
+ }
+
+ @Test
+ public void bigIntAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
bigInteger, cos);
+ replay(cos);
+ cos.setMaxSize(bigInteger.longValue());
+ cos.setThreshold(102400L);
+ verify(cos);
+ // Overflow long value
+ bigInteger = bigInteger.add(BigInteger.ONE);
+ cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
bigInteger, cos);
+ replay(cos);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void longAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
Long.MAX_VALUE, cos);
+ replay(cos);
+ cos.setMaxSize(Long.MAX_VALUE);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void integerAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
Integer.MAX_VALUE, cos);
+ replay(cos);
+ cos.setMaxSize(Integer.MAX_VALUE);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void shortAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
Short.MAX_VALUE, cos);
+ replay(cos);
+ cos.setMaxSize(Short.MAX_VALUE);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void byteAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
Byte.MAX_VALUE, cos);
+ replay(cos);
+ cos.setMaxSize(Byte.MAX_VALUE);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void numberStringAsAttachmentMaxSize() throws IOException {
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
"12345", cos);
+ replay(cos);
+ cos.setMaxSize(12345);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test(expected = IOException.class)
+ public void nonNumberStringAsAttachmentMaxSize() throws IOException {
+ try (CachedOutputStream cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+ "test")) {
+ // Will throw exception
+ }
+ }
+
+ @Test(expected = IOException.class)
+ public void objectAsAttachmentMaxSize() throws IOException {
+ try (CachedOutputStream cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+ new Object())) {
+ // Will throw exception
+ }
+ }
+
+ @Test
+ public void fileAsAttachmentDirectory() throws IOException {
+ File attachmentDirectory = new File("/dev/null");
+ CachedOutputStream cos = createMock(CachedOutputStream.class);
+ cos =
testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY,
attachmentDirectory,
+ cos);
+ replay(cos);
+ cos.setOutputDir(attachmentDirectory);
+ cos.setThreshold(102400L);
+ verify(cos);
+ }
+
+ @Test
+ public void stringAsAttachmentDirectory() throws IOException {
+ String attachmentDirectory = "/dev/null";
Review comment:
Maybe for /dev/null we could instead just use something like
Files.createTempDirectory instead - I'm not sure if the former would work
properly on windows?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]