--- /dev/null
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.agent;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.AgentRunningBuild;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPackParameters;\r
+import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import org.jmock.Expectations;\r
+import org.jmock.Mockery;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * @author Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 23.08.11 16:23\r
+ */\r
+public class NuGetPackActionFactoryTest extends BaseTestCase {\r
+ private Mockery m;\r
+ private CommandlineBuildProcessFactory myProcessFactory;\r
+ private NuGetActionFactoryImpl i;\r
+ private BuildRunnerContext ctx;\r
+ private AgentRunningBuild build;\r
+ private NuGetPackParameters myPackParameters;\r
+ private File myFile;\r
+ private File myNuGet;\r
+ private File myRoot;\r
+ private File myOut;\r
+ private File myWorkingDir;\r
+ private Collection<String> myExcludes;\r
+ private Collection<String> myProperties;\r
+ private Collection<String> myExtra;\r
+\r
+\r
+ @BeforeMethod\r
+ @Override\r
+ protected void setUp() throws Exception {\r
+ super.setUp();\r
+ m = new Mockery();\r
+ myProcessFactory = m.mock(CommandlineBuildProcessFactory.class);\r
+ PackageUsages pu = m.mock(PackageUsages.class);\r
+ i = new NuGetActionFactoryImpl(myProcessFactory, pu, new CommandFactoryImpl());\r
+ ctx = m.mock(BuildRunnerContext.class);\r
+ myPackParameters = m.mock(NuGetPackParameters.class);\r
+ build = m.mock(AgentRunningBuild.class);\r
+\r
+ myFile = createTempFile();\r
+ myNuGet = createTempFile();\r
+ myRoot = createTempDir();\r
+ myOut = createTempDir();\r
+ myWorkingDir = createTempDir();\r
+\r
+ myExcludes = new ArrayList<String>();\r
+ myProperties = new ArrayList<String>();\r
+ myExtra = new ArrayList<String>();\r
+\r
+ m.checking(new Expectations(){{\r
+ allowing(ctx).getBuild(); will(returnValue(build));\r
+ allowing(build).getCheckoutDirectory(); will(returnValue(myWorkingDir));\r
+ allowing(myPackParameters).getSpecFile(); will(returnValue(myFile));\r
+ allowing(myPackParameters).getNuGetExeFile(); will(returnValue(myNuGet));\r
+ allowing(myPackParameters).getBaseDirectory(); will(returnValue(myRoot));\r
+ allowing(myPackParameters).getOutputDirectory(); will(returnValue(myOut));\r
+ allowing(myPackParameters).getVersion(); will(returnValue("45.239.32.12"));\r
+\r
+ allowing(myPackParameters).getCustomCommandline(); will(returnValue(myExtra));\r
+ allowing(myPackParameters).getProperties(); will(returnValue(myProperties));\r
+ allowing(myPackParameters).getExclude(); will(returnValue(myExcludes));\r
+ }});\r
+ }\r
+\r
+\r
+ @Test\r
+ public void test_package() throws RunBuildException {\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(false));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_properties() throws RunBuildException {\r
+ myProperties.add("p1=p2");\r
+ myProperties.add("p3=p24");\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(false));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Properties", "p1=p2", "-Properties", "p3=p24")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_custom_commandline() throws RunBuildException {\r
+ myExtra.add("arg1");\r
+ myExtra.add("arg2");\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(false));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "arg1", "arg2")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_excludes() throws RunBuildException {\r
+ myExcludes.add("aaa");\r
+ myExcludes.add("d/v/de");\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(false));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Exclude", "aaa", "-Exclude", "d/v/de")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_package_tool() throws RunBuildException {\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(true));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(false));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Tool")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+ @Test\r
+ public void test_package_symbols() throws RunBuildException {\r
+ m.checking(new Expectations(){{\r
+ allowing(myPackParameters).packTool(); will(returnValue(false));\r
+ allowing(myPackParameters).packSymbols(); will(returnValue(true));\r
+\r
+ oneOf(myProcessFactory).executeCommandLine(ctx, myNuGet,\r
+ Arrays.asList(\r
+ "pack", myFile.getPath(), "-OutputDirectory", myOut.getPath(), "-BasePath", myRoot.getPath(), "-Verbose", "-Version", "45.239.32.12", "-Symbols")\r
+ , myWorkingDir);\r
+ }});\r
+\r
+ i.createPack(ctx, myPackParameters);\r
+ m.assertIsSatisfied();\r
+ }\r
+\r
+}\r