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.agent;
\r
19 import jetbrains.buildServer.BaseTestCase;
\r
20 import jetbrains.buildServer.RunBuildException;
\r
21 import jetbrains.buildServer.agent.AgentRunningBuild;
\r
22 import jetbrains.buildServer.agent.BuildRunnerContext;
\r
23 import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;
\r
24 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;
\r
25 import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;
\r
26 import jetbrains.buildServer.nuget.agent.parameters.NuGetPackParameters;
\r
27 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;
\r
28 import org.jmock.Expectations;
\r
29 import org.jmock.Mockery;
\r
30 import org.testng.annotations.BeforeMethod;
\r
31 import org.testng.annotations.Test;
\r
33 import java.io.File;
\r
34 import java.util.ArrayList;
\r
35 import java.util.Arrays;
\r
36 import java.util.Collection;
\r
37 import java.util.Collections;
\r
40 * @author Eugene Petrenko (eugene.petrenko@gmail.com)
\r
41 * Date: 23.08.11 16:23
\r
43 public class NuGetPackActionFactoryTest extends BaseTestCase {
\r
45 private CommandlineBuildProcessFactory myProcessFactory;
\r
46 private NuGetActionFactoryImpl i;
\r
47 private BuildRunnerContext ctx;
\r
48 private AgentRunningBuild build;
\r
49 private NuGetPackParameters myPackParameters;
\r
50 private File myFile;
\r
51 private File myNuGet;
\r
52 private File myRoot;
\r
54 private File myWorkingDir;
\r
55 private Collection<String> myExcludes;
\r
56 private Collection<String> myProperties;
\r
57 private Collection<String> myExtra;
\r
62 protected void setUp() throws Exception {
\r
65 myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);
\r
66 PackageUsages pu = m.mock(PackageUsages.class);
\r
67 i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());
\r
68 ctx = m.mock(BuildRunnerContext.class);
\r
69 myPackParameters = m.mock(NuGetPackParameters.class);
\r
70 build = m.mock(AgentRunningBuild.class);
\r
72 myFile = createTempFile();
\r
73 myNuGet = createTempFile();
\r
74 myRoot = createTempDir();
\r
75 myOut = createTempDir();
\r
76 myWorkingDir = createTempDir();
\r
78 myExcludes = new ArrayList<String>();
\r
79 myProperties = new ArrayList<String>();
\r
80 myExtra = new ArrayList<String>();
\r
82 m.checking(new Expectations(){{
\r
83 allowing(ctx).getBuild(); will(returnValue(build));
\r
84 allowing(build).getCheckoutDirectory(); will(returnValue(myWorkingDir));
\r
85 allowing(myPackParameters).getSpecFile(); will(returnValue(myFile));
\r
86 allowing(myPackParameters).getNuGetExeFile(); will(returnValue(myNuGet));
\r
87 allowing(myPackParameters).getBaseDirectory(); will(returnValue(myRoot));
\r
88 allowing(myPackParameters).getOutputDirectory(); will(returnValue(myOut));
\r
89 allowing(myPackParameters).getVersion(); will(returnValue("45.239.32.12"));
\r
91 allowing(myPackParameters).getCustomCommandline(); will(returnValue(myExtra));
\r
92 allowing(myPackParameters).getProperties(); will(returnValue(myProperties));
\r
93 allowing(myPackParameters).getExclude(); will(returnValue(myExcludes));
\r
99 public void test_package() throws RunBuildException {
\r
100 m.checking(new Expectations(){{
\r
101 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
102 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
104 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
106 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")
\r
108 Collections.<String, String>emptyMap());
\r
111 i.createPack(ctx, myPackParameters);
\r
112 m.assertIsSatisfied();
\r
116 public void test_properties() throws RunBuildException {
\r
117 myProperties.add("p1=p2");
\r
118 myProperties.add("p3=p24");
\r
119 m.checking(new Expectations(){{
\r
120 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
121 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
123 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
125 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Properties", "p1=p2", "-Properties", "p3=p24")
\r
127 Collections.<String, String>emptyMap());
\r
130 i.createPack(ctx, myPackParameters);
\r
131 m.assertIsSatisfied();
\r
135 public void test_custom_commandline() throws RunBuildException {
\r
136 myExtra.add("arg1");
\r
137 myExtra.add("arg2");
\r
138 m.checking(new Expectations() {{
\r
139 allowing(myPackParameters).packTool();
\r
140 will(returnValue(false));
\r
141 allowing(myPackParameters).packSymbols();
\r
142 will(returnValue(false));
\r
144 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
146 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")
\r
148 Collections.<String, String>emptyMap());
\r
151 i.createPack(ctx, myPackParameters);
\r
152 m.assertIsSatisfied();
\r
156 public void test_excludes() throws RunBuildException {
\r
157 myExcludes.add("aaa");
\r
158 myExcludes.add("d/v/de");
\r
159 m.checking(new Expectations(){{
\r
160 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
161 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
163 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
165 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Exclude", "aaa", "-Exclude", "d/v/de")
\r
167 Collections.<String, String>emptyMap());
\r
170 i.createPack(ctx, myPackParameters);
\r
171 m.assertIsSatisfied();
\r
175 public void test_package_tool() throws RunBuildException {
\r
176 m.checking(new Expectations(){{
\r
177 allowing(myPackParameters).packTool(); will(returnValue(true));
\r
178 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
180 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
182 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")
\r
184 Collections.<String, String>emptyMap());
\r
187 i.createPack(ctx, myPackParameters);
\r
188 m.assertIsSatisfied();
\r
192 public void test_package_symbols() throws RunBuildException {
\r
193 m.checking(new Expectations(){{
\r
194 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
195 allowing(myPackParameters).packSymbols(); will(returnValue(true));
\r
197 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
199 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")
\r
201 Collections.<String, String>emptyMap());
\r
204 i.createPack(ctx, myPackParameters);
\r
205 m.assertIsSatisfied();
\r