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
88 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
89 m.assertIsSatisfied();
\r
93 public void test_packageIds() throws RunBuildException, IOException {
\r
94 final File nuget = createTempFile();
\r
95 m.checking(new Expectations(){{
\r
96 allowing(nugetParams).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
97 allowing(nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
98 allowing(ps).getUseSafeUpdate(); will(returnValue(false));
\r
99 allowing(ps).getPackagesToUpdate(); will(returnValue(Arrays.asList("aaa", "bbb")));
\r
101 oneOf(myProcessFactory).executeCommandLine(
\r
104 Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Id", "aaa", "-Id", "bbb"),
\r
105 myConfig.getParentFile()
\r
109 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
110 m.assertIsSatisfied();
\r
114 public void test_safe() throws RunBuildException, IOException {
\r
115 final File nuget = createTempFile();
\r
116 m.checking(new Expectations(){{
\r
117 allowing(nugetParams).getNuGetPackageSources(); will(returnValue(Collections.<String>emptyList()));
\r
118 allowing(nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
119 allowing(ps).getUseSafeUpdate(); will(returnValue(true));
\r
120 allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));
\r
122 oneOf(myProcessFactory).executeCommandLine(
\r
125 Arrays.asList("update", myConfig.getPath(), "-Safe", "-Verbose", "-RepositoryPath", myTarget.getPath()),
\r
126 myConfig.getParentFile()
\r
130 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
131 m.assertIsSatisfied();
\r
135 public void test_sources() throws RunBuildException, IOException {
\r
136 final File nuget = createTempFile();
\r
137 m.checking(new Expectations(){{
\r
138 allowing(NuGetUpdatePackageActionFactoryTest.this.nugetParams).getNuGetPackageSources(); will(returnValue(Arrays.asList("aaa", "bbb")));
\r
139 allowing(NuGetUpdatePackageActionFactoryTest.this.nugetParams).getNuGetExeFile(); will(returnValue(nuget));
\r
140 allowing(ps).getUseSafeUpdate(); will(returnValue(false));
\r
141 allowing(ps).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));
\r
143 oneOf(myProcessFactory).executeCommandLine(
\r
146 Arrays.asList("update", myConfig.getPath(), "-Verbose", "-RepositoryPath", myTarget.getPath(), "-Source", "aaa", "-Source", "bbb"),
\r
147 myConfig.getParentFile()
\r
151 i.createUpdate(ctx, ps, myConfig, myTarget);
\r
152 m.assertIsSatisfied();
\r