agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/managers/JobRequestInputProcessorIT.java
/**
     * Tests job app input validation on jobs submitted as json
     */
Tests job app input validation on jobs submitted as json
Tests job app input validation on jobs submitted as json
@Test
    public void processJsonJobInputDefaults()
    {
        try {
            SoftwareInput input2 = new SoftwareInput();
            input2.setDefaultValue("/usr/bin/date");
            input2.setKey("hiddenTime");
            input2.setVisible(false);
            input2.setRequired(true);
            SoftwareInput input3 = new SoftwareInput();
            input3.setDefaultValue("/usr/bin/mkdir");
            input3.setKey("optionalKey1");
            input3.setRequired(false);
            SoftwareInput input4 = new SoftwareInput();
            input4.setDefaultValue("/usr/bin/top");
            input4.setKey("requiredKey2");
            input4.setRequired(true);
            SoftwareInput input5 = new SoftwareInput();
            input5.setDefaultValue("/usr/bin/ls");
            input5.setKey("optionalKey2");
            input5.setRequired(false);
            ObjectNode jobInputs = mapper.createObjectNode()
                    .put(input5.getKey(), "wazzup")
                    .put(input4.getKey(), "top")
                    .put("dummyfield", "something");
            ObjectNode processedInputs = _genericProcess(List.of(input2, input3, input4, input5), jobInputs);
            Assert.assertTrue(processedInputs.has(input2.getKey()), "Hidden fields should always be added");
            assertEquals(processedInputs.get(input2.getKey()), input2.getDefaultValueAsJsonArray(), "Hidden fields should always be added");
            assertFalse(processedInputs.has(input3.getKey()), "Optional fields should not be added if user does not supply value");
            assertFalse(processedInputs.has("dummyfield"), "User supplied fields not part of the job should not be persisted.");
            Assert.assertTrue(processedInputs.has(input4.getKey()), "User supplied required fields should be persisted");
            assertEquals(processedInputs.get(input4.getKey()).get(0).textValue(), "top", "Required field that user supplies as input should be the value persisted with the job");
            Assert.assertTrue(processedInputs.has(input5.getKey()), "User supplied optional fields should be persisted");
            assertEquals(processedInputs.get(input5.getKey()).get(0).textValue(), "wazzup", "Option field that user supplies as input should be the value persisted with the job");
        } catch (Exception e) {
            Assert.fail("Failed to process job", e);
        }
    }
@ Test public void processJsonJobInputDefaults ( ) { try { SoftwareInput input2 = new SoftwareInput ( ) ; input2 . setDefaultValue ( "/usr/bin/date" ) ; input2 . setKey ( "hiddenTime" ) ; input2 . setVisible ( false ) ; input2 . setRequired ( true ) ; SoftwareInput input3 = new SoftwareInput ( ) ; input3 . setDefaultValue ( "/usr/bin/mkdir" ) ; input3 . setKey ( "optionalKey1" ) ; input3 . setRequired ( false ) ; SoftwareInput input4 = new SoftwareInput ( ) ; input4 . setDefaultValue ( "/usr/bin/top" ) ; input4 . setKey ( "requiredKey2" ) ; input4 . setRequired ( true ) ; SoftwareInput input5 = new SoftwareInput ( ) ; input5 . setDefaultValue ( "/usr/bin/ls" ) ; input5 . setKey ( "optionalKey2" ) ; input5 . setRequired ( false ) ; ObjectNode jobInputs = mapper . createObjectNode ( ) . put ( input5 . getKey ( ) , "wazzup" ) . put ( input4 . getKey ( ) , "top" ) . put ( "dummyfield" , "something" ) ; ObjectNode processedInputs = _genericProcess ( List . of ( input2 , input3 , input4 , input5 ) , jobInputs ) ; Assert . assertTrue ( processedInputs . has ( input2 . getKey ( ) ) , "Hidden fields should always be added" ) ; assertEquals ( processedInputs . get ( input2 . getKey ( ) ) , input2 . getDefaultValueAsJsonArray ( ) , "Hidden fields should always be added" ) ; assertFalse ( processedInputs . has ( input3 . getKey ( ) ) , "Optional fields should not be added if user does not supply value" ) ; assertFalse ( processedInputs . has ( "dummyfield" ) , "User supplied fields not part of the job should not be persisted." ) ; Assert . assertTrue ( processedInputs . has ( input4 . getKey ( ) ) , "User supplied required fields should be persisted" ) ; assertEquals ( processedInputs . get ( input4 . getKey ( ) ) . get ( 0 ) . textValue ( ) , "top" , "Required field that user supplies as input should be the value persisted with the job" ) ; Assert . assertTrue ( processedInputs . has ( input5 . getKey ( ) ) , "User supplied optional fields should be persisted" ) ; assertEquals ( processedInputs . get ( input5 . getKey ( ) ) . get ( 0 ) . textValue ( ) , "wazzup" , "Option field that user supplies as input should be the value persisted with the job" ) ; } catch ( Exception e ) { Assert . fail ( "Failed to process job" , e ) ; } }
Tests job app input validation on jobs submitted as json
Tests job app input validation on jobs submitted as json