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.install.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
39 * @author Eugene Petrenko (eugene.petrenko@gmail.com)
\r
40 * Date: 23.08.11 16:23
\r
42 public class NuGetPackActionFactoryTest extends BaseTestCase {
\r
44 private CommandlineBuildProcessFactory myProcessFactory;
\r
45 private NuGetActionFactoryImpl i;
\r
46 private BuildRunnerContext ctx;
\r
47 private AgentRunningBuild build;
\r
48 private NuGetPackParameters myPackParameters;
\r
49 private File myFile;
\r
50 private File myNuGet;
\r
51 private File myRoot;
\r
53 private File myWorkingDir;
\r
54 private Collection<String> myExcludes;
\r
55 private Collection<String> myProperties;
\r
56 private Collection<String> myExtra;
\r
61 protected void setUp() throws Exception {
\r
64 myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);
\r
65 PackageUsages pu = m.mock(PackageUsages.class);
\r
66 i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());
\r
67 ctx = m.mock(BuildRunnerContext.class);
\r
68 myPackParameters = m.mock(NuGetPackParameters.class);
\r
69 build = m.mock(AgentRunningBuild.class);
\r
71 myFile = createTempFile();
\r
72 myNuGet = createTempFile();
\r
73 myRoot = createTempDir();
\r
74 myOut = createTempDir();
\r
75 myWorkingDir = createTempDir();
\r
77 myExcludes = new ArrayList<String>();
\r
78 myProperties = new ArrayList<String>();
\r
79 myExtra = new ArrayList<String>();
\r
81 m.checking(new Expectations(){{
\r
82 allowing(ctx).getBuild(); will(returnValue(build));
\r
83 allowing(build).getCheckoutDirectory(); will(returnValue(myWorkingDir));
\r
84 allowing(myPackParameters).getSpecFile(); will(returnValue(myFile));
\r
85 allowing(myPackParameters).getNuGetExeFile(); will(returnValue(myNuGet));
\r
86 allowing(myPackParameters).getBaseDirectory(); will(returnValue(myRoot));
\r
87 allowing(myPackParameters).getOutputDirectory(); will(returnValue(myOut));
\r
88 allowing(myPackParameters).getVersion(); will(returnValue("45.239.32.12"));
\r
90 allowing(myPackParameters).getCustomCommandline(); will(returnValue(myExtra));
\r
91 allowing(myPackParameters).getProperties(); will(returnValue(myProperties));
\r
92 allowing(myPackParameters).getExclude(); will(returnValue(myExcludes));
\r
98 public void test_package() throws RunBuildException {
\r
99 m.checking(new Expectations(){{
\r
100 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
101 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
103 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
105 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")
\r
109 i.createPack(ctx, myPackParameters);
\r
110 m.assertIsSatisfied();
\r
114 public void test_properties() throws RunBuildException {
\r
115 myProperties.add("p1=p2");
\r
116 myProperties.add("p3=p24");
\r
117 m.checking(new Expectations(){{
\r
118 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
119 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
121 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
123 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Properties", "p1=p2", "-Properties", "p3=p24")
\r
127 i.createPack(ctx, myPackParameters);
\r
128 m.assertIsSatisfied();
\r
132 public void test_custom_commandline() throws RunBuildException {
\r
133 myExtra.add("arg1");
\r
134 myExtra.add("arg2");
\r
135 m.checking(new Expectations(){{
\r
136 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
137 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
139 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
141 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")
\r
145 i.createPack(ctx, myPackParameters);
\r
146 m.assertIsSatisfied();
\r
150 public void test_excludes() throws RunBuildException {
\r
151 myExcludes.add("aaa");
\r
152 myExcludes.add("d/v/de");
\r
153 m.checking(new Expectations(){{
\r
154 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
155 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
157 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
159 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Exclude", "aaa", "-Exclude", "d/v/de")
\r
163 i.createPack(ctx, myPackParameters);
\r
164 m.assertIsSatisfied();
\r
168 public void test_package_tool() throws RunBuildException {
\r
169 m.checking(new Expectations(){{
\r
170 allowing(myPackParameters).packTool(); will(returnValue(true));
\r
171 allowing(myPackParameters).packSymbols(); will(returnValue(false));
\r
173 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
175 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")
\r
179 i.createPack(ctx, myPackParameters);
\r
180 m.assertIsSatisfied();
\r
184 public void test_package_symbols() throws RunBuildException {
\r
185 m.checking(new Expectations(){{
\r
186 allowing(myPackParameters).packTool(); will(returnValue(false));
\r
187 allowing(myPackParameters).packSymbols(); will(returnValue(true));
\r
189 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,
\r
191 "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")
\r
195 i.createPack(ctx, myPackParameters);
\r
196 m.assertIsSatisfied();
\r