diff --git a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/DefaultFortifyCLIRunner.java b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/DefaultFortifyCLIRunner.java index d724aaade5..334d455558 100644 --- a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/DefaultFortifyCLIRunner.java +++ b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/DefaultFortifyCLIRunner.java @@ -22,13 +22,12 @@ import com.fortify.cli.common.rest.unirest.GenericUnirestFactory; import com.fortify.cli.common.variable.FcliVariableHelper; -import lombok.AccessLevel; -import lombok.Getter; import picocli.CommandLine; public final class DefaultFortifyCLIRunner implements IFortifyCLIRunner { - @Getter(value = AccessLevel.PRIVATE, lazy = true) - private final CommandLine commandLine = createCommandLine(); + // TODO See https://github.com/remkop/picocli/issues/2066 + //@Getter(value = AccessLevel.PRIVATE, lazy = true) + //private final CommandLine commandLine = createCommandLine(); private CommandLine createCommandLine() { FortifyCLIStaticInitializer.getInstance().initialize(); @@ -42,7 +41,8 @@ private CommandLine createCommandLine() { public int run(String... args) { String[] resolvedArgs = FcliVariableHelper.resolveVariables(args); FortifyCLIDynamicInitializer.getInstance().initialize(resolvedArgs); - CommandLine cl = getCommandLine(); + //CommandLine cl = getCommandLine(); // TODO See https://github.com/remkop/picocli/issues/2066 + CommandLine cl = createCommandLine(); cl.clearExecutionResults(); return cl.execute(resolvedArgs); } diff --git a/fcli-other/fcli-functional-test/build.gradle b/fcli-other/fcli-functional-test/build.gradle index 67b7bdc815..f453251272 100644 --- a/fcli-other/fcli-functional-test/build.gradle +++ b/fcli-other/fcli-functional-test/build.gradle @@ -23,7 +23,7 @@ testing { } options { testLogging { - showStandardStreams = true + showStandardStreams = false } } } diff --git a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsGetSpec.groovy b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsGetSpec.groovy new file mode 100644 index 0000000000..0c2cc65fb6 --- /dev/null +++ b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsGetSpec.groovy @@ -0,0 +1,176 @@ +package com.fortify.cli.ftest.core; + +import com.fortify.cli.ftest._common.Fcli +import com.fortify.cli.ftest._common.Fcli.FcliResult +import com.fortify.cli.ftest._common.spec.FcliBaseSpec +import com.fortify.cli.ftest._common.spec.Prefix + +// TODO Add/improve tests, and reduce duplication between OutputOptionsGetSpec/OutputOptionsListSpec. +// Some ideas, in particular for table/csv-based tests: +// - Check for array of expected words on each line, i.e. splitting the input on spaces/comma's +// - Define expected array of words for headers and particular records in fields, i.e. +// expectedWordsRecordId0, expectedWordsLastRecord, expectedWordsTableHeader, expectedWordsCsvHeader +// - Define methods for performing certain checks, i.e. hasAllWords(line, expectedWords), ... +// - Share all of the above between List/GetSpecs, for example through helper class, abstract base class, +// or combining both get and list tests in single spec? +@Prefix("core.output.get") +class OutputOptionsGetSpec extends FcliBaseSpec { + private static final FcliResult generate(String outputFormat) { + def args = ["util", "sample-data", "get", "0"] + if ( outputFormat!=null ) { args+=["-o", outputFormat] } + return Fcli.runOrFail(args) + } + + def "table.no-opts"() { + when: + def result = generate("table") + then: + verifyAll(result.stdout) { + size()==2 + it[0].contains('Id String value Long value Double value Boolean value Date value Date time value Nested object string value Nested object boolean value Nested string aray') + it[1].contains('0 value1 1000 0.7 true 2000-01-01 2000-01-01T00:00:00+00:00 nestedObjectValue1 true nestedArrayValue3, nestedArrayValue4') + } + } + + def "table-plain.no-opts"() { + def outputArg = "table-plain" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + size()==1 + it[0].contains('0 value1 1000 0.7 true 2000-01-01 2000-01-01T00:00:00+00:00 nestedObjectValue1 true nestedArrayValue3, nestedArrayValue4') + } + } + + def "csv.no-opts"() { + def outputArg = "csv" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + size()==2 + it[0] == 'id,stringValue,longValue,doubleValue,booleanValue,dateValue,dateTimeValue,nestedObjectStringValue,nestedObjectBooleanValue,nestedStringAray' + it[1] == '0,value1,1000,0.7,true,2000-01-01,"2000-01-01T00:00:00+00:00",nestedObjectValue1,true,"nestedArrayValue3, nestedArrayValue4"' + } + } + + def "csv-plain.no-opts"() { + def outputArg = "csv-plain" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + size()==1 + it[0] == '0,value1,1000,0.7,true,2000-01-01,"2000-01-01T00:00:00+00:00",nestedObjectValue1,true,"nestedArrayValue3, nestedArrayValue4"' + } + } + + def "json.no-opts"() { + def outputArg = "json" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "json-flat.no-opts"() { + def outputArg = "json-flat" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "tree.no-opts"() { + def outputArg = "tree" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "tree-flat.no-opts"() { + def outputArg = "tree-flat" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "xml.no-opts"() { + def outputArg = "xml" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "xml-flat.no-opts"() { + def outputArg = "xml-flat" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "yaml.no-opts"(String outputArg) { + // For now, Yaml is the default output for get operations; if this is ever + // changed (see comment at StandardOutputConfig#details), the where-block + // below will need to be moved to the appropriate method in this spec. + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + where: + outputArg | _ + "yaml" | _ + null | _ + } + + def "yaml-flat.no-opts"() { + def outputArg = "table-plain" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + // TODO Add expectations + } + } + + def "expr"() { + def outputArg = "expr={id}: {stringValue}" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + size()==1 + it[0] == '0: value1' + } + } + + def "json-properties"() { + def outputArg = "json-properties" + when: + def result = generate(outputArg) + then: + verifyAll(result.stdout) { + size()==20 + // TODO Add expectations + } + } +} \ No newline at end of file diff --git a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/ListOutputOptionsSpec.groovy b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsListSpec.groovy similarity index 95% rename from fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/ListOutputOptionsSpec.groovy rename to fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsListSpec.groovy index c8ed51ce9b..5481d251dd 100644 --- a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/ListOutputOptionsSpec.groovy +++ b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/OutputOptionsListSpec.groovy @@ -5,11 +5,12 @@ import com.fortify.cli.ftest._common.Fcli.FcliResult import com.fortify.cli.ftest._common.spec.FcliBaseSpec import com.fortify.cli.ftest._common.spec.Prefix +// TODO See comments in OutputOptionsGetSpec @Prefix("core.output.list") -class ListOutputOptionsSpec extends FcliBaseSpec { - private FcliResult generate(String outputArg) { - def args = ["util", "sample-data", "list"] as String[] - if ( outputArg!=null ) { args+=["-o", outputArg] } +class OutputOptionsListSpec extends FcliBaseSpec { + private static final FcliResult generate(String outputFormat) { + def args = ["util", "sample-data", "list"] + if ( outputFormat!=null ) { args+=["-o", outputFormat] } return Fcli.runOrFail(args) } diff --git a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/QuerySpec.groovy b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/QuerySpec.groovy index 1853b73de1..2ff49c8f9e 100644 --- a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/QuerySpec.groovy +++ b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/core/QuerySpec.groovy @@ -1,16 +1,28 @@ package com.fortify.cli.ftest.core; import com.fortify.cli.ftest._common.Fcli +import com.fortify.cli.ftest._common.Fcli.FcliResult import com.fortify.cli.ftest._common.spec.FcliBaseSpec import com.fortify.cli.ftest._common.spec.Prefix @Prefix("core.query") class QuerySpec extends FcliBaseSpec { + private static final FcliResult generate(String query) { + def args = ["util", "sample-data", "list"] + if ( query!=null ) { args+=["-q", query] } + return Fcli.runOrFail(args) + } + def "contains"() { - expect: - // TODO Implement this (and many other) spec, using sample data from - // "fcli util sample-data list", making sure that we cover for - // example https://github.com/fortify/fcli/issues/344 - true + when: + def result = generate("{'value1',null}.contains(stringValue)") + then: + verifyAll(result.stdout) { + size()==15553 + it[0].contains('Id String value Long value Double value Boolean value Date value Date time value Nested object string value Nested object boolean value Nested string aray') + it[1].contains('0 value1 1000 0.7 true 2000-01-01 2000-01-01T00:00:00+00:00 nestedObjectValue1 true nestedArrayValue3, nestedArrayValue4') + it[15552].contains('23327 N/A N/A N/A N/A N/A N/A N/A N/A') + } } + } \ No newline at end of file