nuget publish runner integration test added
[teamcity/dotNetPackagesSupport.git] / nuget-tests / src / jetbrains / buildServer / nuget / tests / integration / InstallPackageIntegtatoinTest.java
1 /*\r
2  * Copyright 2000-2011 JetBrains s.r.o.\r
3  *\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
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 package jetbrains.buildServer.nuget.tests.integration;\r
18 \r
19 import jetbrains.buildServer.RunBuildException;\r
20 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
21 import jetbrains.buildServer.agent.BuildProcess;\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.install.PackageUsages;\r
25 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
26 import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
27 import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;\r
28 import jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl;\r
29 import jetbrains.buildServer.nuget.common.PackageInfo;\r
30 import jetbrains.buildServer.nuget.common.PackagesUpdateMode;\r
31 import jetbrains.buildServer.util.ArchiveUtil;\r
32 import org.jetbrains.annotations.Nullable;\r
33 import org.jmock.Expectations;\r
34 import org.testng.Assert;\r
35 import org.testng.annotations.Test;\r
36 \r
37 import java.io.File;\r
38 import java.util.*;\r
39 \r
40 /**\r
41  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
42  * Date: 08.07.11 2:15\r
43  */\r
44 public class InstallPackageIntegtatoinTest extends IntegrationTestBase {\r
45 \r
46   @Test\r
47   public void test_01_online_sources() throws RunBuildException {\r
48     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
49 \r
50     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, false,\r
51             Arrays.asList(\r
52                     new PackageInfo("Machine.Specifications", "0.4.13.0"),\r
53                     new PackageInfo("NUnit", "2.5.7.10213"),\r
54                     new PackageInfo("Ninject", "2.2.1.4"))\r
55     );\r
56 \r
57     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
58     System.out.println("installed packageses = " + packageses);\r
59 \r
60     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
61     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
62     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
63     Assert.assertEquals(4, packageses.size());\r
64   }\r
65 \r
66   @Test\r
67   public void test_01_online_sources_update_forConfig() throws RunBuildException {\r
68     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
69 \r
70     m.checking(new Expectations() {{\r
71       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
72       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
73 \r
74       allowing(myUpdate).getUseSafeUpdate(); will(returnValue(false));\r
75       allowing(myUpdate).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
76       allowing(myUpdate).getUpdateMode(); will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
77     }});\r
78 \r
79     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
80 \r
81 \r
82     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
83     System.out.println("installed packageses = " + packageses);\r
84 \r
85     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
86     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.10.11092").isDirectory());\r
87     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
88     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
89     Assert.assertEquals(5, packageses.size());\r
90   }\r
91 \r
92   @Test\r
93   public void test_01_online_sources_update_forSln() throws RunBuildException {\r
94     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
95 \r
96     m.checking(new Expectations() {{\r
97       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
98       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
99 \r
100       allowing(myUpdate).getUseSafeUpdate();\r
101       will(returnValue(false));\r
102       allowing(myUpdate).getPackagesToUpdate();\r
103       will(returnValue(Collections.<String>emptyList()));\r
104       allowing(myUpdate).getUpdateMode();\r
105       will(returnValue(PackagesUpdateMode.FOR_SLN));\r
106     }});\r
107 \r
108     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
109 \r
110 \r
111     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
112     System.out.println("installed packageses = " + packageses);\r
113 \r
114     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
115     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.10.11092").isDirectory());\r
116     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
117     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
118     Assert.assertEquals(5, packageses.size());\r
119   }\r
120 \r
121   @Test\r
122   public void test_01_online_sources_update_safe() throws RunBuildException {\r
123     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
124 \r
125     m.checking(new Expectations() {{\r
126       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
127       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
128 \r
129       allowing(myUpdate).getUseSafeUpdate();\r
130       will(returnValue(true));\r
131       allowing(myUpdate).getPackagesToUpdate();\r
132       will(returnValue(Collections.<String>emptyList()));\r
133       allowing(myUpdate).getUpdateMode();\r
134       will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
135     }});\r
136 \r
137     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
138 \r
139 \r
140     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
141     System.out.println("installed packageses = " + packageses);\r
142 \r
143     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
144     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.10.11092").isDirectory());\r
145     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
146     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
147     Assert.assertEquals(5, packageses.size());\r
148   }\r
149 \r
150   @Test\r
151   public void test_01_online_sources_ecludeVersion() throws RunBuildException {\r
152     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
153 \r
154     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true, false,\r
155             Arrays.asList(\r
156                     new PackageInfo("Machine.Specifications", "0.4.13.0"),\r
157                     new PackageInfo("NUnit", "2.5.7.10213"),\r
158                     new PackageInfo("Ninject", "2.2.1.4")));\r
159 \r
160     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
161     System.out.println("installed packageses = " + packageses);\r
162 \r
163     Assert.assertTrue(new File(myRoot, "packages/NUnit").isDirectory());\r
164     Assert.assertTrue(new File(myRoot, "packages/NInject").isDirectory());\r
165     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications").isDirectory());\r
166     Assert.assertEquals(4, packageses.size());\r
167   }\r
168 \r
169   @Test(enabled = false, dependsOnGroups = "Need to understand how to check NuGet uses only specified sources")\r
170   public void test_01_local_sources() throws RunBuildException {\r
171     ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
172     File sourcesDir = new File(myRoot, "js");\r
173     ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01-sources.zip"), "", sourcesDir);\r
174 \r
175     fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false, false, null);\r
176 \r
177     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
178     System.out.println("installed packageses = " + packageses);\r
179 \r
180     Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
181     Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
182     Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
183     Assert.assertEquals(4, packageses.size());\r
184   }\r
185 \r
186   private void fetchPackages(final File sln,\r
187                              final List<String> sources,\r
188                              final boolean excludeVersion,\r
189                              final boolean update,\r
190                              @Nullable Collection<PackageInfo> detectedPackages) throws RunBuildException {\r
191 \r
192     m.checking(new Expectations() {{\r
193       allowing(myParametersFactory).loadNuGetFetchParameters(myContext);\r
194       will(returnValue(myNuGet));\r
195       allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);\r
196       will(returnValue(myInstall));\r
197 \r
198       allowing(myNuGet).getNuGetExeFile();\r
199       will(returnValue(Paths.getPathToNuGet()));\r
200       allowing(myNuGet).getSolutionFile();\r
201       will(returnValue(sln));\r
202       allowing(myNuGet).getNuGetPackageSources();\r
203       will(returnValue(sources));\r
204       allowing(myInstall).getExcludeVersion();\r
205       will(returnValue(excludeVersion));\r
206       allowing(myParametersFactory).loadUpdatePackagesParameters(myContext, myNuGet);\r
207       will(returnValue(update ? myUpdate : null));\r
208     }});\r
209 \r
210     NuGetPackagesCollectorImpl collector = new NuGetPackagesCollectorImpl();\r
211     PackageUsages pu = new PackageUsagesImpl(\r
212             collector,\r
213             new NuGetPackagesConfigParser()\r
214     );\r
215 \r
216     BuildProcess proc = new PackagesInstallerRunner(\r
217             new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()),\r
218             myParametersFactory\r
219     ).createBuildProcess(myBuild, myContext);\r
220 \r
221     assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
222 \r
223     System.out.println(collector.getPackages());\r
224     if (detectedPackages != null) {\r
225       Assert.assertEquals(\r
226               new TreeSet<PackageInfo>(collector.getPackages().getPackages()),\r
227               new TreeSet<PackageInfo>(detectedPackages));\r
228     }\r
229 \r
230     m.assertIsSatisfied();\r
231   }\r
232 \r
233 }\r