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.BuildRunnerContext;
\r
22 import jetbrains.buildServer.nuget.agent.install.PackagesInstallParameters;
\r
23 import jetbrains.buildServer.nuget.agent.install.impl.NuGetInstallPackageActionFactoryImpl;
\r
24 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;
\r
25 import org.jmock.Expectations;
\r
26 import org.jmock.Mockery;
\r
27 import org.testng.annotations.BeforeMethod;
\r
28 import org.testng.annotations.Test;
\r
30 import java.io.File;
\r
31 import java.io.IOException;
\r
32 import java.util.Arrays;
\r
33 import java.util.Collections;
\r
36 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
37 * Date: 08.07.11 1:36
\r
39 public class NuGetInstallPackageActionFactoryTest extends BaseTestCase {
\r
41 private CommandlineBuildProcessFactory myProcessFactory;
\r
42 private NuGetInstallPackageActionFactoryImpl i;
\r
43 private BuildRunnerContext ctx;
\r
44 private PackagesInstallParameters ps;
\r
45 private File myTarget;
\r
46 private File myConfig;
\r
50 protected void setUp() throws Exception {
\r
53 myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);
\r
54 i = new NuGetInstallPackageActionFactoryImpl(myProcessFactory);
\r
55 ctx = m.mock(BuildRunnerContext.class);
\r
56 ps = m.mock(PackagesInstallParameters.class);
\r
58 myTarget = createTempDir();
\r
59 myConfig = createTempFile();
\r
63 public void test_no_sources() throws RunBuildException, IOException {
\r
64 final File nuget = createTempFile();
\r
65 m.checking(new Expectations(){{
\r
66 allowing(ps).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
67 allowing(ps).getNuGetExeFile(); will(returnValue(nuget));
\r
69 oneOf(myProcessFactory).executeCommandLine(
\r
72 Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath()),
\r
73 myConfig.getParentFile()
\r
77 i.createBuildProcess(ctx, ps, myConfig, myTarget);
\r
78 m.assertIsSatisfied();
\r
82 public void test_sources() throws RunBuildException, IOException {
\r
83 final File nuget = createTempFile();
\r
84 m.checking(new Expectations(){{
\r
85 allowing(ps).getNuGetPackageSources(); will(returnValue(Arrays.asList("aaa", "bbb")));
\r
86 allowing(ps).getNuGetExeFile(); will(returnValue(nuget));
\r
88 oneOf(myProcessFactory).executeCommandLine(
\r
91 Arrays.asList("install", myConfig.getPath(), "-OutputDirectory", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),
\r
92 myConfig.getParentFile()
\r
96 i.createBuildProcess(ctx, ps, myConfig, myTarget);
\r
97 m.assertIsSatisfied();
\r