2 * Copyright 2000-2011 JetBrains s.r.o.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package jetbrains.buildServer.nuget.tests.integration;
\r
19 import com.intellij.execution.configurations.GeneralCommandLine;
\r
20 import jetbrains.buildServer.ExecResult;
\r
21 import jetbrains.buildServer.RunBuildException;
\r
22 import jetbrains.buildServer.SimpleCommandLineProcessRunner;
\r
23 import jetbrains.buildServer.agent.*;
\r
24 import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;
\r
25 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;
\r
26 import jetbrains.buildServer.nuget.agent.commands.impl.LoggingNuGetActionFactoryImpl;
\r
27 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;
\r
28 import jetbrains.buildServer.nuget.agent.dependencies.NuGetPackagesCollector;
\r
29 import jetbrains.buildServer.nuget.agent.dependencies.impl.NuGetPackagesCollectorImpl;
\r
30 import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;
\r
31 import jetbrains.buildServer.nuget.agent.dependencies.impl.NuGetPackagesConfigParser;
\r
32 import jetbrains.buildServer.nuget.agent.dependencies.impl.PackageUsagesImpl;
\r
33 import jetbrains.buildServer.nuget.agent.parameters.*;
\r
34 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;
\r
35 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;
\r
36 import jetbrains.buildServer.nuget.tests.util.BuildProcessTestCase;
\r
37 import org.jetbrains.annotations.NotNull;
\r
38 import org.jmock.Expectations;
\r
39 import org.jmock.Mockery;
\r
40 import org.testng.annotations.BeforeMethod;
\r
42 import java.io.File;
\r
43 import java.util.Collection;
\r
46 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
47 * Date: 22.07.11 1:26
\r
49 public class IntegrationTestBase extends BuildProcessTestCase {
\r
50 private StringBuilder myCommandsOutput;
\r
51 protected File myRoot;
\r
52 protected Mockery m;
\r
53 protected AgentRunningBuild myBuild;
\r
54 protected BuildRunnerContext myContext;
\r
55 protected BuildProgressLogger myLogger;
\r
56 protected PackagesParametersFactory myParametersFactory;
\r
57 protected NuGetFetchParameters myNuGet;
\r
58 protected NuGetPackagesCollector myCollector;
\r
59 protected NuGetActionFactory myActionFactory;
\r
60 private BuildProcess myMockProcess;
\r
63 protected String getCommandsOutput() {
\r
64 return myCommandsOutput.toString();
\r
69 protected void setUp() throws Exception {
\r
71 myCommandsOutput = new StringBuilder();
\r
72 myRoot = createTempDir();
\r
74 myBuild = m.mock(AgentRunningBuild.class);
\r
75 myContext = m.mock(BuildRunnerContext.class);
\r
76 myLogger = m.mock(BuildProgressLogger.class);
\r
77 myParametersFactory = m.mock(PackagesParametersFactory.class);
\r
78 myMockProcess = m.mock(BuildProcess.class);
\r
79 myNuGet = m.mock(NuGetFetchParameters.class);
\r
81 m.checking(new Expectations() {{
\r
82 allowing(myContext).getBuild();
\r
83 will(returnValue(myBuild));
\r
84 allowing(myBuild).getBuildLogger();
\r
85 will(returnValue(myLogger));
\r
86 allowing(myBuild).getCheckoutDirectory();
\r
87 will(returnValue(myRoot));
\r
89 allowing(myMockProcess).start();
\r
90 allowing(myMockProcess).waitFor();
\r
91 will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));
\r
93 allowing(myLogger).message(with(any(String.class)));
\r
96 myCollector = new NuGetPackagesCollectorImpl();
\r
97 PackageUsages pu = new PackageUsagesImpl(
\r
99 new NuGetPackagesConfigParser()
\r
102 myActionFactory = new LoggingNuGetActionFactoryImpl(new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()));
\r
106 protected File getTestDataPath(final String path) {
\r
107 return Paths.getTestDataPath("integration/" + path);
\r
111 private CommandlineBuildProcessFactory executingFactory() {
\r
112 return new CommandlineBuildProcessFactory() {
\r
114 public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,
\r
115 @NotNull final File program,
\r
116 @NotNull final Collection<String> argz,
\r
117 @NotNull final File workingDir) throws RunBuildException {
\r
118 return new BuildProcessBase() {
\r
121 protected BuildFinishedStatus waitForImpl() throws RunBuildException {
\r
122 GeneralCommandLine cmd = new GeneralCommandLine();
\r
123 cmd.setExePath(program.getPath());
\r
124 for (String arg : argz) {
\r
125 cmd.addParameter(arg);
\r
127 cmd.setWorkingDirectory(workingDir);
\r
129 System.out.println("Run: " + cmd.getCommandLineString());
\r
131 ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);
\r
133 System.out.println(result.getStdout());
\r
134 System.out.println(result.getStderr());
\r
136 myCommandsOutput.append(result.getStdout()).append("\n\n").append(result.getStderr()).append("\n\n");
\r
138 return result.getExitCode() == 0
\r
139 ? BuildFinishedStatus.FINISHED_SUCCESS
\r
140 : BuildFinishedStatus.FINISHED_FAILED;
\r