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.RunBuildException;
\r
20 import jetbrains.buildServer.agent.BuildFinishedStatus;
\r
21 import jetbrains.buildServer.agent.BuildProgressLogger;
\r
22 import jetbrains.buildServer.nuget.agent.install.LocateNuGetConfigBuildProcess;
\r
23 import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;
\r
24 import jetbrains.buildServer.nuget.tests.util.BuildProcessTestCase;
\r
25 import jetbrains.buildServer.util.FileUtil;
\r
26 import org.jmock.Expectations;
\r
27 import org.jmock.Mockery;
\r
28 import org.testng.annotations.BeforeMethod;
\r
29 import org.testng.annotations.Test;
\r
31 import java.io.File;
\r
34 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
\r
35 * Date: 07.07.11 20:49
\r
37 public class LocateNuGetConfigBuildProcessTest extends BuildProcessTestCase {
\r
38 private File myRoot;
\r
40 private BuildProgressLogger log;
\r
41 private NuGetParameters ps;
\r
42 private LocateNuGetConfigBuildProcess.Callback cb;
\r
43 private LocateNuGetConfigBuildProcess proc;
\r
47 protected void setUp() throws Exception {
\r
49 myRoot = createTempDir();
\r
51 log = m.mock(BuildProgressLogger.class);
\r
52 ps = m.mock(NuGetParameters.class);
\r
53 cb = m.mock(LocateNuGetConfigBuildProcess.Callback.class);
\r
54 proc = new LocateNuGetConfigBuildProcess(ps, log, cb);
\r
58 public void test_no_solutionFile() throws RunBuildException {
\r
59 m.checking(new Expectations() {{
\r
60 allowing(ps).getSolutionFile();
\r
61 will(returnValue(new File(myRoot, "foo.sln")));
\r
64 assertRunException(proc, "Failed to find");
\r
65 m.assertIsSatisfied();
\r
69 public void test_only_solutionFile() throws RunBuildException {
\r
70 final File sln = new File(myRoot, "foo.sln");
\r
72 FileUtil.writeFile(sln, "Fake solution file");
\r
73 m.checking(new Expectations() {{
\r
74 allowing(ps).getSolutionFile();
\r
75 will(returnValue(sln));
\r
77 oneOf(cb).onSolutionFileFound(sln, new File(sln.getParentFile(), "packages"));
\r
80 assertRunException(proc, "Failed to find repositories.config");
\r
81 m.assertIsSatisfied();
\r
85 public void test_solutionFile_packages_empty() throws RunBuildException {
\r
86 final File sln = new File(myRoot, "foo.sln");
\r
87 final File packages = new File(sln.getParentFile(), "packages");
\r
90 FileUtil.writeFile(sln, "Fake solution file");
\r
91 m.checking(new Expectations() {{
\r
92 allowing(ps).getSolutionFile();
\r
93 will(returnValue(sln));
\r
95 oneOf(cb).onSolutionFileFound(sln, packages);
\r
98 assertRunException(proc, "Failed to find repositories.config");
\r
99 m.assertIsSatisfied();
\r
103 public void test_solutionFile_repositories_config_empty() throws RunBuildException {
\r
104 final File sln = new File(myRoot, "foo.sln");
\r
105 final File packages = new File(sln.getParentFile(), "packages");
\r
107 final File repositories = new File(packages, "repositories.config");
\r
109 FileUtil.writeFile(repositories, "<foo />");
\r
111 FileUtil.writeFile(sln, "Fake solution file");
\r
112 m.checking(new Expectations() {{
\r
113 allowing(ps).getSolutionFile();
\r
114 will(returnValue(sln));
\r
116 oneOf(cb).onSolutionFileFound(sln, packages);
\r
118 allowing(log).message(with(new StartsWithMatcher("Found packages folder: ")));
\r
119 allowing(log).message(with(new StartsWithMatcher("Found list of packages.config files: ")));
\r
120 allowing(log).warning(with(new StartsWithMatcher("No packages.config files were found under solution.")));
\r
123 assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);
\r
124 m.assertIsSatisfied();
\r
127 public void test_solutionFile_repositories_config_empty2() throws RunBuildException {
\r
128 final File sln = new File(myRoot, "foo.sln");
\r
129 final File packages = new File(sln.getParentFile(), "packages");
\r
131 final File repositories = new File(packages, "repositories.config");
\r
133 FileUtil.writeFile(repositories, "<foo /");
\r
135 FileUtil.writeFile(sln, "Fake solution file");
\r
136 m.checking(new Expectations() {{
\r
137 allowing(ps).getSolutionFile();
\r
138 will(returnValue(sln));
\r
140 oneOf(cb).onSolutionFileFound(sln, packages);
\r
142 allowing(log).message(with(new StartsWithMatcher("Found packages folder: ")));
\r
143 allowing(log).message(with(new StartsWithMatcher("Found list of packages.config files: ")));
\r
144 allowing(log).warning(with(new StartsWithMatcher("No packages.config files were found under solution.")));
\r
147 assertRunException(proc, "Failed to parse repositories.config at ");
\r
148 m.assertIsSatisfied();
\r
152 public void test_solutionFile_repositories_config_no_packages_config() throws RunBuildException {
\r
153 final File sln = new File(myRoot, "foo.sln");
\r
154 final File packages = new File(sln.getParentFile(), "packages");
\r
156 final File repositories = new File(packages, "repositories.config");
\r
158 FileUtil.writeFile(repositories,
\r
159 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
\r
160 "<repositories>\n" +
\r
161 " <repository path=\"..\\Mvc\\packages.config\" />\n" +
\r
162 " <repository path=\"c:\\Mvc2\\packages.config\" />\n" +
\r
163 "</repositories>");
\r
165 FileUtil.writeFile(sln, "Fake solution file");
\r
166 m.checking(new Expectations() {{
\r
167 allowing(ps).getSolutionFile();
\r
168 will(returnValue(sln));
\r
170 oneOf(cb).onSolutionFileFound(sln, packages);
\r
171 oneOf(cb).onPackagesConfigFound(new File(myRoot, "Mvc/packages.config"), packages);
\r
172 oneOf(cb).onPackagesConfigFound(new File("c:\\Mvc2/packages.config"), packages);
\r
174 allowing(log).message(with(new StartsWithMatcher("Found packages folder: ")));
\r
175 allowing(log).message(with(new StartsWithMatcher("Found list of packages.config files: ")));
\r
176 allowing(log).warning(with(new StartsWithMatcher("No packages.config files were found under solution.")));
\r
179 assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);
\r
180 m.assertIsSatisfied();
\r