@Test public void testWithNullInput() { final Map<String, String> execute = arraySize.execute(null); assertEquals("The input value is not a valid JavaScript array!", execute.get(RETURN_RESULT)); assertEquals("The input value is not a valid JavaScript array!", execute.get("exception")); assertEquals("-1", execute.get("returnCode")); }
@Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); }
ArraySize { @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); } }
ArraySize { @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); }  }
ArraySize { @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); }  @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array); }
ArraySize { @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); }  @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array); static final String NOT_A_VALID_JSON_ARRAY_MESSAGE; }