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.NuGetPublishParameters;
\r
26 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;
\r
27 import org.jmock.Expectations;
\r
28 import org.jmock.Mockery;
\r
29 import org.testng.annotations.BeforeMethod;
\r
30 import org.testng.annotations.Test;
\r
32 import java.io.File;
\r
33 import java.util.Arrays;
\r
36 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
37 * Date: 21.07.11 16:46
\r
39 public class NuGetPushActoinFactoryTest extends BaseTestCase {
\r
41 private CommandlineBuildProcessFactory myProcessFactory;
\r
42 private NuGetActionFactoryImpl i;
\r
43 private BuildRunnerContext ctx;
\r
44 private NuGetPublishParameters ps;
\r
45 private File myFile;
\r
46 private File myNuGet;
\r
50 protected void setUp() throws Exception {
\r
53 myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);
\r
54 PackageUsages pu = m.mock(PackageUsages.class);
\r
55 i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());
\r
56 ctx = m.mock(BuildRunnerContext.class);
\r
57 ps = m.mock(NuGetPublishParameters.class);
\r
59 myFile = createTempFile();
\r
60 myNuGet = createTempFile();
\r
64 public void test_command_push() throws RunBuildException {
\r
65 m.checking(new Expectations(){{
\r
66 allowing(ps).getNuGetExeFile(); will(returnValue(myNuGet));
\r
67 allowing(ps).getApiKey(); will(returnValue("api-key-guid"));
\r
68 allowing(ps).getPublishSource(); will(returnValue("push-feed"));
\r
69 allowing(ps).getCreateOnly(); will(returnValue(false));
\r
71 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-Source", "push-feed"), myFile.getParentFile());
\r
74 i.createPush(ctx, ps, myFile);
\r
76 m.assertIsSatisfied();
\r
80 public void test_command_push_no_source() throws RunBuildException {
\r
81 m.checking(new Expectations(){{
\r
82 allowing(ps).getNuGetExeFile(); will(returnValue(myNuGet));
\r
83 allowing(ps).getApiKey(); will(returnValue("api-key-guid"));
\r
84 allowing(ps).getPublishSource(); will(returnValue(null));
\r
85 allowing(ps).getCreateOnly(); will(returnValue(false));
\r
87 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid"), myFile.getParentFile());
\r
90 i.createPush(ctx, ps, myFile);
\r
92 m.assertIsSatisfied();
\r
96 public void test_command_push_no_pacakge() throws RunBuildException {
\r
97 m.checking(new Expectations(){{
\r
98 allowing(ps).getNuGetExeFile(); will(returnValue(myNuGet));
\r
99 allowing(ps).getApiKey(); will(returnValue("api-key-guid"));
\r
100 allowing(ps).getPublishSource(); will(returnValue("push-feed"));
\r
101 allowing(ps).getCreateOnly(); will(returnValue(true));
\r
103 oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet, Arrays.asList("push", myFile.getPath(), "api-key-guid", "-CreateOnly", "-Source", "push-feed"), myFile.getParentFile());
\r
106 i.createPush(ctx, ps, myFile);
\r
108 m.assertIsSatisfied();
\r