integration test 001 added
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 22:54:28 +0000 (02:54 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 22:54:28 +0000 (02:54 +0400)
.idea/libraries/Idea_OpenApi.xml
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java [new file with mode: 0644]

index e6fb2c954861970230c0cd1895aec24b97fd71e7..7cdf0cd1c96f3294bcb399fca88ed901c4b3dde1 100644 (file)
@@ -3,6 +3,7 @@
     <CLASSES>\r
       <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/util.jar!/" />\r
       <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/openapi.jar!/" />\r
+      <root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/trove4j.jar!/" />\r
     </CLASSES>\r
     <JAVADOC />\r
     <SOURCES />\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java
new file mode 100644 (file)
index 0000000..1a7556a
--- /dev/null
@@ -0,0 +1,170 @@
+/*\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.integration;\r
+\r
+import com.intellij.execution.configurations.GeneralCommandLine;\r
+import jetbrains.buildServer.ExecResult;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
+import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.install.PackageInstallParametersFactory;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetInstallPackageActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
+import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import jetbrains.buildServer.nuget.tests.util.BuildProcessTestCase;\r
+import jetbrains.buildServer.util.ArchiveUtil;\r
+import jetbrains.buildServer.util.FileUtil;\r
+import junit.framework.Assert;\r
+import org.jetbrains.annotations.NotNull;\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.Arrays;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 08.07.11 2:15\r
+ */\r
+public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {\r
+  private File myRoot;\r
+  private Mockery m;\r
+  private AgentRunningBuild myBuild;\r
+  private BuildRunnerContext myContext;\r
+  private BuildProgressLogger myLogger;\r
+  private PackageInstallParametersFactory myParametersFactory;\r
+  private PackagesInstallParameters myParameters;\r
+  private BuildProcess myMockProcess;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    myRoot = createTempDir();\r
+    m = new Mockery();\r
+    myBuild = m.mock(AgentRunningBuild.class);\r
+    myContext = m.mock(BuildRunnerContext.class);\r
+    myLogger = m.mock(BuildProgressLogger.class);\r
+    myParametersFactory = m.mock(PackageInstallParametersFactory.class);\r
+    myParameters = m.mock(PackagesInstallParameters.class);\r
+    myMockProcess = m.mock(BuildProcess.class);\r
+\r
+    m.checking(new Expectations() {{\r
+      allowing(myContext).getBuild();\r
+      will(returnValue(myBuild));\r
+      allowing(myBuild).getBuildLogger();\r
+      will(returnValue(myLogger));\r
+\r
+      allowing(myMockProcess).start();\r
+      allowing(myMockProcess).waitFor(); will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));\r
+\r
+      allowing(myLogger).message(with(any(String.class)));\r
+      allowing(myLogger).activityStarted(with(equal("install")), with(any(String.class)), with(any(String.class)));\r
+      allowing(myLogger).activityFinished(with(equal("install")), with(any(String.class)));\r
+    }});\r
+  }\r
+\r
+  @Test\r
+  public void test_01_online_sources() throws RunBuildException {\r
+    ArchiveUtil.unpackZip(getTestDataPath("test-01.zip"), "", myRoot);\r
+    final File sln = new File(myRoot, "sln1-lib.sln");\r
+\r
+    m.checking(new Expectations() {{\r
+      allowing(myParametersFactory).loadParameters(myContext);\r
+      will(returnValue(myParameters));\r
+\r
+      allowing(myParameters).getNuGetExeFile();\r
+      will(returnValue(getPathToNuGet()));\r
+      allowing(myParameters).getSolutionFile();\r
+      will(returnValue(sln));\r
+      allowing(myParameters).getNuGetPackageSources();\r
+      will(returnValue(Collections.<String>emptyList()));\r
+    }});\r
+\r
+    BuildProcess proc = new PackagesInstallerRunner(\r
+            new NuGetInstallPackageActionFactoryImpl(executingFactory()),\r
+            myParametersFactory\r
+    )\r
+            .createBuildProcess(myBuild, myContext);\r
+\r
+    assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
+\r
+    m.assertIsSatisfied();\r
+\r
+    List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
+    System.out.println("installed packageses = " + packageses);\r
+\r
+    Assert.assertTrue(new File(myRoot, "packages/NUnit.2.5.7.10213").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/NInject.2.2.1.4").isDirectory());\r
+    Assert.assertTrue(new File(myRoot, "packages/Machine.Specifications.0.4.13.0").isDirectory());\r
+    Assert.assertEquals(4, packageses.size());\r
+  }\r
+\r
+\r
+  @NotNull\r
+  private File getTestDataPath() {\r
+    return FileUtil.getCanonicalFile(new File("./nuget-tests/testData/integration"));\r
+  }\r
+\r
+  @NotNull\r
+  private File getTestDataPath(@NotNull final String p) {\r
+    return FileUtil.getCanonicalFile(new File(getTestDataPath(), p));\r
+  }\r
+\r
+  @NotNull\r
+  private File getPathToNuGet() {\r
+    return FileUtil.getCanonicalFile(new File("./nuget-tests/testData/nuget/1.4/NuGet.exe"));\r
+  }\r
+\r
+  private CommandlineBuildProcessFactory executingFactory() {\r
+    return new CommandlineBuildProcessFactory() {\r
+      public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,\r
+                                             @NotNull final File program,\r
+                                             @NotNull final Collection<String> argz,\r
+                                             @NotNull final File workingDir) throws RunBuildException {\r
+        return new BuildProcessBase() {\r
+          @NotNull\r
+          @Override\r
+          protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
+            GeneralCommandLine cmd = new GeneralCommandLine();\r
+            cmd.setExePath(program.getPath());\r
+            for (String arg : argz) {\r
+              cmd.addParameter(arg);\r
+            }\r
+            cmd.setWorkingDirectory(workingDir);\r
+\r
+            ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);\r
+\r
+            System.out.println(result.getStdout());\r
+            System.out.println(result.getStderr());\r
+\r
+            return result.getExitCode() == 0\r
+                    ? BuildFinishedStatus.FINISHED_SUCCESS\r
+                    : BuildFinishedStatus.FINISHED_FAILED;\r
+          }\r
+        };\r
+      }\r
+    };\r
+  }\r
+}\r