diff --git a/src/main/java/org/icatproject/ids/enums/ValueContainerType.java b/src/main/java/org/icatproject/ids/enums/ValueContainerType.java index 3b76ca27..cf7501ac 100644 --- a/src/main/java/org/icatproject/ids/enums/ValueContainerType.java +++ b/src/main/java/org/icatproject/ids/enums/ValueContainerType.java @@ -4,5 +4,5 @@ * This enum provides all possible values of a ValueContainer */ public enum ValueContainerType { - INVALID, VOID, INT, LONG, BOOL, STRING, REQUEST, RESPONSE, INPUTSTREAM + INVALID, VOID, INT, LONG, BOOL, STRING, RESPONSE, INPUTSTREAM } diff --git a/src/main/java/org/icatproject/ids/helpers/ValueContainer.java b/src/main/java/org/icatproject/ids/helpers/ValueContainer.java index 33d8a212..bb99efba 100644 --- a/src/main/java/org/icatproject/ids/helpers/ValueContainer.java +++ b/src/main/java/org/icatproject/ids/helpers/ValueContainer.java @@ -5,7 +5,6 @@ import org.icatproject.ids.enums.ValueContainerType; import org.icatproject.ids.exceptions.InternalException; -import jakarta.servlet.http.HttpServletRequest; import jakarta.ws.rs.core.Response; /** @@ -78,14 +77,6 @@ public ValueContainer(boolean value) { this(value, ValueContainerType.BOOL); } - /** - * Creates a ValueContainer of type Request - * @param value the value contained by the container - */ - public ValueContainer(HttpServletRequest value) { - this(value, ValueContainerType.REQUEST); - } - /** * Creates a ValueContainer of type Response * @param value the value contained by the container @@ -150,16 +141,6 @@ public String getString() throws InternalException { return (String) this.value; } - /** - * Tries to return the value of the type Request. - * @return - * @throws InternalException if the container has another type an exception will be thrown - */ - public HttpServletRequest getRequest() throws InternalException { - this.checkType(ValueContainerType.REQUEST); - return (HttpServletRequest) this.value; - } - /** * Tries to return the value of the type Response. * @return @@ -189,7 +170,6 @@ public String toString() { case LONG: return ""+this.value; case BOOL: return ((boolean)this.value ? "true" : "false"); case STRING: return (String)this.value; - case REQUEST: return "HttpServletRequest: " + ((HttpServletRequest) this.value).getQueryString(); case RESPONSE: return "Response " + ((Response) this.value).toString(); case INPUTSTREAM: return "An InputStream which will be printed here to prevent it from closing (and maybe it is too long)."; default: diff --git a/src/test/java/org/icatproject/ids/TestValueContainer.java b/src/test/java/org/icatproject/ids/TestValueContainer.java index 8dc72fd7..bc3daf98 100644 --- a/src/test/java/org/icatproject/ids/TestValueContainer.java +++ b/src/test/java/org/icatproject/ids/TestValueContainer.java @@ -4,13 +4,19 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + import org.icatproject.ids.enums.ValueContainerType; import org.icatproject.ids.exceptions.InternalException; import org.icatproject.ids.helpers.ValueContainer; import org.junit.Test; -public class TestValueContainer { +public class TestValueContainer { @Test public void testInvalidValueContainer() throws Exception { @@ -65,7 +71,7 @@ public void testBoolValueContainer() throws Exception { assertEquals(vc.getBool(), true); - vc.getInt(); + vc.getString(); } @Test(expected = InternalException.class) @@ -80,4 +86,26 @@ public void testStringValueContainer() throws Exception { vc.getBool(); } + + @Test(expected = InternalException.class) + public void testInputStreamValueContainer() throws Exception { + + String s = "test InputStream"; + var inputStream = new ByteArrayInputStream(s.getBytes()); + var vc = new ValueContainer(inputStream); + assertFalse(vc.isVoid()); + assertFalse(vc.isInvalid()); + assertFalse(vc.isNull()); + + assertEquals(vc.getInputStream(), inputStream); + + var ISReader = new InputStreamReader(vc.getInputStream(), StandardCharsets.UTF_8); + var BReader = new BufferedReader(ISReader); + String textFromStream = BReader.lines().collect(Collectors.joining()); + BReader.close(); + assertEquals(textFromStream, s); + + vc.getString(); + } + } \ No newline at end of file