DotTraceSetupBuilder implements CommandLineSetupBuilder { @Override @NotNull public Iterable<CommandLineSetup> build(@NotNull final CommandLineSetup baseSetup) { if(myAssertions.contains(RunnerAssertions.Assertion.PROFILING_IS_NOT_ALLOWED)) { return Collections.singleton(baseSetup); } final String dotTraceTool = myParametersService.tryGetRunnerParameter(Constants.USE_VAR); if (StringUtil.isEmptyOrSpaces(dotTraceTool) || !Boolean.parseBoolean(dotTraceTool)) { return Collections.singleton(baseSetup); } final List<CommandLineResource> resources = new ArrayList<CommandLineResource>(baseSetup.getResources()); final File cmdFile = myFileService.getTempFileName(DOT_TRACE_CMD_EXT); final File projectFile = myFileService.getTempFileName(DOT_TRACE_PROJECT_EXT); final File snapshotFileDir = myFileService.getTempFileName(""); if(!myFileService.exists(snapshotFileDir)) { snapshotFileDir.mkdirs(); } final File snapshotFile = new File(snapshotFileDir, DOT_TRACE_SNAPSHOT_FILE); final File patternsFile = myFileService.getTempFileName(DOT_TRACE_PATTERNS_EXT); final File reportFile = myFileService.getTempFileName(DOT_TRACE_REPORT_EXT); final Context ctx = new Context(baseSetup, projectFile, snapshotFile, patternsFile, reportFile); resources.add(new CommandLineFile(myBeforeBuildPublisher, projectFile, myProjectGenerator.create(ctx))); resources.add(new CommandLineFile(myBeforeBuildPublisher, patternsFile, myPatternGenerator.create(ctx))); resources.add(new CommandLineFile(myBeforeBuildPublisher, cmdFile, myCmdGenerator.create(ctx))); resources.add(new CommandLineArtifact(myDotTraceBuildPublisher, reportFile)); resources.add(new CommandLineArtifact(myDotTraceSnapshotsPublisher, snapshotFile)); return Collections.singleton(new CommandLineSetup(cmdFile.getPath(), Collections.<CommandLineArgument>emptyList(), resources)); } DotTraceSetupBuilder(
    @NotNull final ResourceGenerator<Context> projectGenerator,
    @NotNull final ResourceGenerator<Context> patternGenerator,
    @NotNull final ResourceGenerator<Context> cmdGenerator,
    @NotNull final ResourcePublisher beforeBuildPublisher,
    @NotNull final ResourcePublisher dotTraceBuildPublisher,
    @NotNull final ResourcePublisher dotTraceSnapshotsPublisher,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final FileService fileService,
    @NotNull final RunnerAssertions assertions); @Override @NotNull Iterable<CommandLineSetup> build(@NotNull final CommandLineSetup baseSetup);  }
@Test public void shouldCreateSetupWhenGetSetup() { final CommandLineSetup baseSetup = new CommandLineSetup("someTool", Arrays.asList(new CommandLineArgument("/arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("/arg2", CommandLineArgument.Type.PARAMETER)), Collections.singletonList(myCommandLineResource)); final File cmdFile = new File("cmd"); final File projectFile = new File("project"); final File snapshotDir = new File("snapshotRoot"); final File snapshotFile = new File(snapshotDir, DotTraceSetupBuilder.DOT_TRACE_SNAPSHOT_FILE); final File patternsFile = new File("patterns"); final File reportFile = new File("report"); final Context ctx = new Context(baseSetup, projectFile, snapshotFile, patternsFile, reportFile); myCtx.checking(new Expectations() {{ oneOf(myAssertions).contains(RunnerAssertions.Assertion.PROFILING_IS_NOT_ALLOWED); will(returnValue(false)); oneOf(myRunnerParametersService).tryGetRunnerParameter(Constants.USE_VAR); will(returnValue("True")); oneOf(myFileService).getTempFileName(DotTraceSetupBuilder.DOT_TRACE_CMD_EXT); will(returnValue(cmdFile)); oneOf(myFileService).getTempFileName(DotTraceSetupBuilder.DOT_TRACE_PROJECT_EXT); will(returnValue(projectFile)); oneOf(myFileService).getTempFileName(""); will(returnValue(snapshotDir)); oneOf(myFileService).exists(snapshotDir); will(returnValue(true)); oneOf(myFileService).getTempFileName(DotTraceSetupBuilder.DOT_TRACE_PATTERNS_EXT); will(returnValue(patternsFile)); oneOf(myFileService).getTempFileName(DotTraceSetupBuilder.DOT_TRACE_REPORT_EXT); will(returnValue(reportFile)); oneOf(myProjectGenerator).create(ctx); will(returnValue("project's content")); oneOf(myPatternsGenerator).create(ctx); will(returnValue("patterns' content")); oneOf(myCmdGenerator).create(ctx); will(returnValue("cmd's content")); }}); final DotTraceSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(baseSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup.getToolPath()).isEqualTo(cmdFile.getPath()); then(setup.getArgs()).isEmpty(); then(setup.getResources()).containsExactly( myCommandLineResource, new CommandLineFile(myBeforeBuildPublisher, projectFile, "project's content"), new CommandLineFile(myBeforeBuildPublisher, patternsFile, "patterns' content"), new CommandLineFile(myBeforeBuildPublisher, cmdFile, "cmd's content"), new CommandLineArtifact(myDotTraceBuildPublisher, reportFile), new CommandLineArtifact(myDotTraceSnapshotsPublisher, snapshotFile)); }
@Test(dataProvider = "runnerParamUseDotTraceCases") public void shouldReturnBaseSetupWhenRunnerParamUseDotTraceIsEmptyOrFalse(final String useDotTrace) { final CommandLineSetup baseSetup = new CommandLineSetup("someTool", Arrays.asList(new CommandLineArgument("/arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("/arg2", CommandLineArgument.Type.PARAMETER)), Collections.singletonList(myCommandLineResource)); myCtx.checking(new Expectations() {{ oneOf(myAssertions).contains(RunnerAssertions.Assertion.PROFILING_IS_NOT_ALLOWED); will(returnValue(false)); oneOf(myRunnerParametersService).tryGetRunnerParameter(Constants.USE_VAR); will(returnValue(useDotTrace)); }}); final DotTraceSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(baseSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup).isEqualTo(baseSetup); }
@Test public void shouldReturnBaseSetupWhenProfilingIsNotAllowed() { final CommandLineSetup baseSetup = new CommandLineSetup("someTool", Arrays.asList(new CommandLineArgument("/arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("/arg2", CommandLineArgument.Type.PARAMETER)), Collections.singletonList(myCommandLineResource)); myCtx.checking(new Expectations() {{ oneOf(myAssertions).contains(RunnerAssertions.Assertion.PROFILING_IS_NOT_ALLOWED); will(returnValue(true)); }}); final DotTraceSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(baseSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup).isEqualTo(baseSetup); }