GetSignedUrlTaskParameters extends GetUrlTaskParameters { public static GetSignedUrlTaskParameters deserialize(String taskParameters) { JaxbJsonSerializer<GetSignedUrlTaskParameters> serializer = new JaxbJsonSerializer<>(GetSignedUrlTaskParameters.class); try { GetSignedUrlTaskParameters params = serializer.deserialize(taskParameters); if (null == params.getSpaceId() || params.getSpaceId().isEmpty()) { throw new TaskDataException( "Task parameter 'spaceId' may not be empty"); } else if (null == params.getContentId() || params.getContentId().isEmpty()) { throw new TaskDataException( "Task parameter 'contentId' may not be empty"); } return params; } catch (IOException e) { throw new TaskDataException( "Unable to parse task parameters due to: " + e.getMessage()); } } GetSignedUrlTaskParameters(); String getSpaceId(); void setSpaceId(String spaceId); String getContentId(); void setContentId(String contentId); String getResourcePrefix(); void setResourcePrefix(String resourcePrefix); int getMinutesToExpire(); void setMinutesToExpire(int minutesToExpire); String getIpAddress(); void setIpAddress(String ipAddress); String serialize(); static GetSignedUrlTaskParameters deserialize(String taskParameters); static final int USE_DEFAULT_MINUTES_TO_EXPIRE; }
@Test public void testDeserialize() { String taskParamsSerialized = "{\"spaceId\" : \"" + spaceId + "\"," + " \"contentId\" : \"" + contentId + "\"," + " \"resourcePrefix\" : \"" + resourcePrefix + "\"," + " \"minutesToExpire\" : " + minutesToExpire + "," + " \"ipAddress\" : \"" + ipAddress + "\"}"; GetSignedUrlTaskParameters taskParams = GetSignedUrlTaskParameters.deserialize(taskParamsSerialized); assertEquals(spaceId, taskParams.getSpaceId()); assertEquals(contentId, taskParams.getContentId()); assertEquals(resourcePrefix, taskParams.getResourcePrefix()); assertEquals(minutesToExpire, taskParams.getMinutesToExpire()); assertEquals(ipAddress, taskParams.getIpAddress()); taskParamsSerialized = "{\"spaceId\" : \"\"," + " \"contentId\" : \"\"," + " \"resourcePrefix\" : \"\"," + " \"minutesToExpire\" : \"\"," + " \"ipAddress\" : \"\"}"; try { GetSignedUrlTaskParameters.deserialize(taskParamsSerialized); fail("Exception expected: Invalid params"); } catch (TaskDataException e) { } try { GetSignedUrlTaskParameters.deserialize(""); fail("Exception expected: Invalid params"); } catch (TaskDataException e) { } }