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.commands.impl.CommandFactoryImpl;
\r
23 import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;
\r
24 import jetbrains.buildServer.nuget.agent.dependencies.PackageUsages;
\r
25 import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters;
\r
26 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;
\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.io.IOException;
\r
35 import java.util.Arrays;
\r
36 import java.util.Collections;
\r
39 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
40 * Date: 10.07.11 14:29
\r
42 public class NuGetUpdatePackageActionFactoryTest extends BaseTestCase {
\r
44 private CommandlineBuildProcessFactory myProcessFactory;
\r
45 private NuGetActionFactoryImpl i;
\r
46 private BuildRunnerContext ctx;
\r
47 private NuGetFetchParameters nugetParams;
\r
48 private PackagesUpdateParameters ps;
\r
49 private File myTarget;
\r
50 private File myConfig;
\r
54 protected void setUp() throws Exception {
\r
57 myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);
\r
58 PackageUsages pu = m.mock(PackageUsages.class);
\r
59 i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());
\r
60 ctx = m.mock(BuildRunnerContext.class);
\r
61 ps = m.mock(PackagesUpdateParameters.class);
\r
62 nugetParams = m.mock(NuGetFetchParameters.class);
\r
64 myTarget = createTempDir();
\r
65 myConfig = createTempFile();
\r
66 m.checking(new Expectations(){{
\r
67 allowing(ps).getNuGetParameters(); will(returnValue(nugetParams));
\r
72 public void test_no_sources() throws RunBuildException, IOException {
\r
73 final File nuget = createTempFile();
\r
74 m.checking(new Expectations(){{
\r
75 allowing(nugetParams).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
76 allowing(nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
77 allowing(ps).getUseSafeUpdate(); will(returnValue(false));
\r
78 allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));
\r
80 oneOf(myProcessFactory).executeCommandLine(
\r
83 Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath()),
\r
84 myConfig.getParentFile(),
\r
85 Collections.<String, String>emptyMap()
\r
89 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
90 m.assertIsSatisfied();
\r
94 public void test_packageIds() throws RunBuildException, IOException {
\r
95 final File nuget = createTempFile();
\r
96 m.checking(new Expectations(){{
\r
97 allowing(nugetParams).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
98 allowing(nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
99 allowing(ps).getUseSafeUpdate(); will(returnValue(false));
\r
100 allowing(ps).getPackagesToUpdate(); will(returnValue(Arrays.asList("aaa", "bbb")));
\r
102 oneOf(myProcessFactory).executeCommandLine(
\r
105 Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),
\r
106 myConfig.getParentFile(),
\r
107 Collections.<String, String>emptyMap()
\r
111 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
112 m.assertIsSatisfied();
\r
116 public void test_safe() throws RunBuildException, IOException {
\r
117 final File nuget = createTempFile();
\r
118 m.checking(new Expectations(){{
\r
119 allowing(nugetParams).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
120 allowing(nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
121 allowing(ps).getUseSafeUpdate(); will(returnValue(true));
\r
122 allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));
\r
124 oneOf(myProcessFactory).executeCommandLine(
\r
127 Arrays.asList("update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),
\r
128 myConfig.getParentFile(),
\r
129 Collections.<String, String>emptyMap()
\r
133 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
134 m.assertIsSatisfied();
\r
138 public void test_sources() throws RunBuildException, IOException {
\r
139 final File nuget = createTempFile();
\r
140 m.checking(new Expectations(){{
\r
141 allowing(NuGetUpdatePackageActionFactoryTest.this.nugetParams).getNuGetPackageSources(); will(returnValue(Arrays.asList("aaa", "bbb")));
\r
142 allowing(NuGetUpdatePackageActionFactoryTest.this.nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
143 allowing(ps).getUseSafeUpdate(); will(returnValue(false));
\r
144 allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));
\r
146 oneOf(myProcessFactory).executeCommandLine(
\r
149 Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),
\r
150 myConfig.getParentFile(),
\r
151 Collections.<String, String>emptyMap()
\r
155 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
156 m.assertIsSatisfied();
\r