@Test public void testBuild() { final Record request = mock(Record.class); when(request.getName()).thenReturn("mock_request"); final Record reply = mock(Record.class); when(reply.getName()).thenReturn("mock_reply"); builder.addWithReplace("request", request); builder.addWithReplace("reply", reply); final String executionCommand = String.format("execute %s", SCRIPT_NAME); final List<String> replyFirst = new ArrayList<String>(2); replyFirst.add("WITH REPLACE(\"REPLY\", \"MOCK_REPLY\")"); replyFirst.add(", REPLACE(\"REQUEST\", \"MOCK_REQUEST\")"); final List<String> requestFirst = new ArrayList<String>(2); requestFirst.add("WITH REPLACE(\"REQUEST\", \"MOCK_REQUEST\")"); requestFirst.add(", REPLACE(\"REPLY\", \"MOCK_REPLY\")"); final List<String> commands = new ArrayList<String>(builder.build()); assertThat(commands).hasSize(4); assertThat(commands.get(0)).isEqualTo(executionCommand); assertThat(commands.get(3)).isEqualTo("go;script_name"); final List<String> replaceCommands = commands.subList(1, 3); if (replaceCommands.get(0).equals(requestFirst.get(0))) { assertThat(replaceCommands).isEqualTo(requestFirst); } else if (replaceCommands.get(0).equals(replyFirst.get(0))) { assertThat(replaceCommands).isEqualTo(replyFirst); } else { fail("First line of replace commands does not match any known value: " + replaceCommands.get(0)); } }
public Collection<String> build() { final List<String> commands = new ArrayList<String>(); commands.add(String.format("execute %s", getScriptName())); if (!arguments.isEmpty()) { final Iterator<Argument> argumentIterator = arguments.iterator(); commands.add(argumentIterator.next().getCommandLineValue()); while (argumentIterator.hasNext()) commands.add("," + argumentIterator.next().getCommandLineValue()); } if (!records.isEmpty()) { final Iterator<Entry<String, Record>> iterator = getRecordStructures().entrySet().iterator(); Entry<String, Record> entry = iterator.next(); commands.add(String.format("WITH REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); while (iterator.hasNext()) { entry = iterator.next(); commands.add(String.format(", REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); } } commands.add("go;" + getScriptName()); return commands; }
ScriptExecutionBuilder { public Collection<String> build() { final List<String> commands = new ArrayList<String>(); commands.add(String.format("execute %s", getScriptName())); if (!arguments.isEmpty()) { final Iterator<Argument> argumentIterator = arguments.iterator(); commands.add(argumentIterator.next().getCommandLineValue()); while (argumentIterator.hasNext()) commands.add("," + argumentIterator.next().getCommandLineValue()); } if (!records.isEmpty()) { final Iterator<Entry<String, Record>> iterator = getRecordStructures().entrySet().iterator(); Entry<String, Record> entry = iterator.next(); commands.add(String.format("WITH REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); while (iterator.hasNext()) { entry = iterator.next(); commands.add(String.format(", REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); } } commands.add("go;" + getScriptName()); return commands; } }
ScriptExecutionBuilder { public Collection<String> build() { final List<String> commands = new ArrayList<String>(); commands.add(String.format("execute %s", getScriptName())); if (!arguments.isEmpty()) { final Iterator<Argument> argumentIterator = arguments.iterator(); commands.add(argumentIterator.next().getCommandLineValue()); while (argumentIterator.hasNext()) commands.add("," + argumentIterator.next().getCommandLineValue()); } if (!records.isEmpty()) { final Iterator<Entry<String, Record>> iterator = getRecordStructures().entrySet().iterator(); Entry<String, Record> entry = iterator.next(); commands.add(String.format("WITH REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); while (iterator.hasNext()) { entry = iterator.next(); commands.add(String.format(", REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); } } commands.add("go;" + getScriptName()); return commands; } private  ScriptExecutionBuilder(final String scriptName); }
ScriptExecutionBuilder { public Collection<String> build() { final List<String> commands = new ArrayList<String>(); commands.add(String.format("execute %s", getScriptName())); if (!arguments.isEmpty()) { final Iterator<Argument> argumentIterator = arguments.iterator(); commands.add(argumentIterator.next().getCommandLineValue()); while (argumentIterator.hasNext()) commands.add("," + argumentIterator.next().getCommandLineValue()); } if (!records.isEmpty()) { final Iterator<Entry<String, Record>> iterator = getRecordStructures().entrySet().iterator(); Entry<String, Record> entry = iterator.next(); commands.add(String.format("WITH REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); while (iterator.hasNext()) { entry = iterator.next(); commands.add(String.format(", REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); } } commands.add("go;" + getScriptName()); return commands; } private  ScriptExecutionBuilder(final String scriptName); static ScriptExecutionBuilder getBuilder(final String scriptName); void addWithReplace(final String recordName, final Record record); Collection<String> build(); String getScriptName(); ScriptExecutionBuilder withArguments(final List<Argument> arguments); }
ScriptExecutionBuilder { public Collection<String> build() { final List<String> commands = new ArrayList<String>(); commands.add(String.format("execute %s", getScriptName())); if (!arguments.isEmpty()) { final Iterator<Argument> argumentIterator = arguments.iterator(); commands.add(argumentIterator.next().getCommandLineValue()); while (argumentIterator.hasNext()) commands.add("," + argumentIterator.next().getCommandLineValue()); } if (!records.isEmpty()) { final Iterator<Entry<String, Record>> iterator = getRecordStructures().entrySet().iterator(); Entry<String, Record> entry = iterator.next(); commands.add(String.format("WITH REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); while (iterator.hasNext()) { entry = iterator.next(); commands.add(String.format(", REPLACE(\"%s\", \"%s\")", entry.getKey(), entry.getValue().getName().toUpperCase(Locale.getDefault()))); } } commands.add("go;" + getScriptName()); return commands; } private  ScriptExecutionBuilder(final String scriptName); static ScriptExecutionBuilder getBuilder(final String scriptName); void addWithReplace(final String recordName, final Record record); Collection<String> build(); String getScriptName(); ScriptExecutionBuilder withArguments(final List<Argument> arguments);  }