CompleteRestoreTaskParameters extends BaseDTO { public static CompleteRestoreTaskParameters deserialize(String taskParameters) { JaxbJsonSerializer<CompleteRestoreTaskParameters> serializer = new JaxbJsonSerializer<>(CompleteRestoreTaskParameters.class); try { CompleteRestoreTaskParameters params = serializer.deserialize(taskParameters); if (null == params.getSpaceId() || params.getSpaceId().isEmpty()) { throw new SnapshotDataException( "Task parameter values may not be empty"); } if (params.getDaysToExpire() < 0) { throw new SnapshotDataException( "Task parameter value must be a positive integer"); } return params; } catch (IOException e) { throw new SnapshotDataException( "Unable to parse task parameters due to: " + e.getMessage()); } } CompleteRestoreTaskParameters(); String getSpaceId(); void setSpaceId(String spaceId); int getDaysToExpire(); void setDaysToExpire(int daysToExpire); String serialize(); static CompleteRestoreTaskParameters deserialize(String taskParameters);  }
@Test public void testDeserialize() { String taskParamsSerialized = "{\"spaceId\" : \"test-space\", " + "\"daysToExpire\" : 20}"; CompleteRestoreTaskParameters taskParams = CompleteRestoreTaskParameters.deserialize(taskParamsSerialized); assertEquals("test-space", taskParams.getSpaceId()); assertEquals(20, taskParams.getDaysToExpire()); taskParamsSerialized = "{\"spaceId\" : \"test-space\", " + "\"daysToExpire\" : -1}"; try { CompleteRestoreTaskParameters.deserialize(taskParamsSerialized); fail("Exception expected: Invalid params"); } catch (SnapshotDataException e) { } taskParamsSerialized = "{\"spaceId\" : \"\"}"; try { CompleteRestoreTaskParameters.deserialize(taskParamsSerialized); fail("Exception expected: Invalid params"); } catch (SnapshotDataException e) { } try { CompleteRestoreTaskParameters.deserialize(""); fail("Exception expected: Invalid params"); } catch (SnapshotDataException e) { } }