tests on packages.config parsing
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 22:26:43 +0000 (02:26 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 22:26:43 +0000 (02:26 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageInfo.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPackagesConfigParserTest.java [new file with mode: 0644]
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/Paths.java
nuget-tests/src/testng-nuget-tests..xml
nuget-tests/testData/config/test-01.xml [new file with mode: 0644]
nuget-tests/testData/config/test-02.xml [new file with mode: 0644]
nuget-tests/testData/config/test-03.xml [new file with mode: 0644]
nuget-tests/testData/config/test-04.xml [new file with mode: 0644]

index 596da407815bf5a1c42cc4961fcb9ce16c8e2e4a..a39609a48cfb85bcc5a09fd2287cda5c7c9e3e3b 100644 (file)
@@ -64,4 +64,12 @@ public class PackageInfo implements Comparable<PackageInfo> {
     result = 31 * result + myVersion.hashCode();\r
     return result;\r
   }\r
+\r
+  @Override\r
+  public String toString() {\r
+    return "PackageInfo{" +\r
+            "myId='" + myId + '\'' +\r
+            ", myVersion='" + myVersion + '\'' +\r
+            '}';\r
+  }\r
 }\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPackagesConfigParserTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/NuGetPackagesConfigParserTest.java
new file mode 100644 (file)
index 0000000..20eb061
--- /dev/null
@@ -0,0 +1,76 @@
+/*\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.nuget.agent.install.PackageInfo;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;\r
+import jetbrains.buildServer.nuget.tests.integration.Paths;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.testng.Assert;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.IOException;\r
+import java.util.Arrays;\r
+import java.util.TreeSet;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 19.07.11 2:01\r
+ */\r
+public class NuGetPackagesConfigParserTest extends BaseTestCase {\r
+\r
+  @Test\r
+  public void test_01() throws IOException {\r
+    doTest("test-01.xml", new PackageInfo("elmah", "1.1"));\r
+  }\r
+\r
+  @Test\r
+  public void test_02() throws IOException {\r
+    doTest("test-02.xml", new PackageInfo("elmah", "1.1"));\r
+  }\r
+\r
+  @Test\r
+  public void test_03() throws IOException {\r
+    doTest("test-03.xml",\r
+            new PackageInfo("Machine.Specifications", "0.4.13.0"),\r
+            new PackageInfo("NUnit", "2.5.7.10213")\r
+            )    ;\r
+  }\r
+\r
+  @Test\r
+  public void test_04() throws IOException {\r
+    doTest("test-04.xml",\r
+            new PackageInfo("EasyHttp", "1.0.6"),\r
+            new PackageInfo("JsonFx", "2.0.1106.2610"),\r
+            new PackageInfo("structuremap", "2.6.2"));\r
+  }\r
+\r
+  public void doTest(@NotNull String testData,\r
+                     @NotNull PackageInfo... packages) throws IOException {\r
+    NuGetPackagesConfigParser p = new NuGetPackagesConfigParser();\r
+    NuGetPackagesCollectorImpl i = new NuGetPackagesCollectorImpl();\r
+    p.parseNuGetPackages(Paths.getTestDataPath("config/" + testData), i);\r
+\r
+    if (packages.length != i.getPackages().size()) {\r
+      System.out.println(i.getPackages());\r
+    }\r
+\r
+    Assert.assertEquals(i.getPackages(), new TreeSet<PackageInfo>(Arrays.asList(packages)));\r
+  }\r
+}\r
index 92039146866893d0e37976a65a41e9e06fb7af5f..89790dc54d71b38b12f85bbcb47be6e431c21e56 100644 (file)
@@ -96,7 +96,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
   @Test\r
   public void test_01_online_sources() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, false);\r
 \r
@@ -109,9 +109,14 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     Assert.assertEquals(4, packageses.size());\r
   }\r
 \r
+  @NotNull\r
+  private File getTestDataPath() {\r
+    return Paths.getTestDataPath("integration/test-01.zip");\r
+  }\r
+\r
   @Test\r
   public void test_01_online_sources_update() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
     m.checking(new Expectations(){{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
@@ -137,7 +142,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
   @Test\r
   public void test_01_online_sources_update_forSln() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
     m.checking(new Expectations(){{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
@@ -163,7 +168,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
   @Test\r
   public void test_01_online_sources_update_safe() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
     m.checking(new Expectations(){{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
@@ -189,7 +194,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
   @Test\r
   public void test_01_online_sources_ecludeVersion() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
     fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true, false);\r
 \r
@@ -204,7 +209,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
   @Test(enabled = false, dependsOnGroups = "Need to understand how to check NuGet uses only specified sources")\r
   public void test_01_local_sources() throws RunBuildException {\r
-    ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01.zip"), "", myRoot);\r
+    ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
     File sourcesDir = new File(myRoot, "js");\r
     ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01-sources.zip"), "", sourcesDir);\r
 \r
index 17b5416d7d2c997ea23b0e118cef57eb16fb87f7..554119d81152edc0e3edc6d1d6958333f897e4cc 100644 (file)
@@ -28,7 +28,7 @@ import java.io.File;
 public class Paths {\r
   @NotNull\r
   public static File getTestDataPath() {\r
-    return FileUtil.getCanonicalFile(new File("./nuget-tests/testData/integration"));\r
+    return FileUtil.getCanonicalFile(new File("./nuget-tests/testData"));\r
   }\r
 \r
   @NotNull\r
index 8c25e055686b7fd3fcad1d02affc1d75228a8727..2d09ef25696594bd446d5c324e69f413e062491f 100644 (file)
@@ -3,6 +3,7 @@
 \r
   <test name="fast tests">\r
     <classes>\r
+      <class name="jetbrains.buildServer.nuget.tests.agent.NuGetPackagesConfigParserTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.LocateNuGetConfigBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.PackagesInstallerBuilderTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
diff --git a/nuget-tests/testData/config/test-01.xml b/nuget-tests/testData/config/test-01.xml
new file mode 100644 (file)
index 0000000..4431598
--- /dev/null
@@ -0,0 +1,4 @@
+\feff<?xml version="1.0" encoding="utf-8"?>\r
+<packages>\r
+  <package id="elmah" version="1.1" />\r
+</packages>
\ No newline at end of file
diff --git a/nuget-tests/testData/config/test-02.xml b/nuget-tests/testData/config/test-02.xml
new file mode 100644 (file)
index 0000000..541a8d6
--- /dev/null
@@ -0,0 +1,4 @@
+\feff<?xml version="1.0" encoding="utf-8"?>\r
+<packages>\r
+  <package id="elmah" version="1.1" allowedVersions="(1.0, 5.5)"/>\r
+</packages>
\ No newline at end of file
diff --git a/nuget-tests/testData/config/test-03.xml b/nuget-tests/testData/config/test-03.xml
new file mode 100644 (file)
index 0000000..1be9c90
--- /dev/null
@@ -0,0 +1,5 @@
+\feff<?xml version="1.0" encoding="utf-8"?>\r
+<packages>\r
+  <package id="Machine.Specifications" version="0.4.13.0" />\r
+  <package id="NUnit" version="2.5.7.10213" allowedVersions="[2.5.0, 2.5.111)" />\r
+</packages>
\ No newline at end of file
diff --git a/nuget-tests/testData/config/test-04.xml b/nuget-tests/testData/config/test-04.xml
new file mode 100644 (file)
index 0000000..51cf381
--- /dev/null
@@ -0,0 +1,6 @@
+\feff<?xml version="1.0" encoding="utf-8"?>\r
+<packages>\r
+  <package id="structuremap" version="2.6.2" />\r
+  <package id="JsonFx" version="2.0.1106.2610" />\r
+  <package id="EasyHttp" version="1.0.6" />\r
+</packages>
\ No newline at end of file