tests for nuget PackageDependenciesStore
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 09:38:14 +0000 (13:38 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 09:38:14 +0000 (13:38 +0400)
nuget-common/src/jetbrains/buildServer/nuget/common/PackageDependenciesStore.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/common/PackageDependenciesStoreTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

index a05589fd5fe6bc4735f307ac855a7051f428bd50..fbe7a357b0e8eb359b642c8a1fe653b5091fb0b1 100644 (file)
@@ -93,11 +93,12 @@ public class PackageDependenciesStore {
     for (String source : deps.getSources()) {\r
       Element src = new Element("source");\r
       src.setText(source);\r
+      sources.addContent((Content)src);\r
     }\r
 \r
     root.addContent((Content)sources);\r
 \r
-    Document doc = new Document(pkgs);\r
+    Document doc = new Document(root);\r
 \r
     OutputStream os = new BufferedOutputStream(new FileOutputStream(file));\r
     try {\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/common/PackageDependenciesStoreTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/common/PackageDependenciesStoreTest.java
new file mode 100644 (file)
index 0000000..42a9d81
--- /dev/null
@@ -0,0 +1,85 @@
+/*\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.common;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.nuget.common.PackageDependencies;\r
+import jetbrains.buildServer.nuget.common.PackageDependenciesStore;\r
+import jetbrains.buildServer.nuget.common.PackageInfo;\r
+import org.testng.Assert;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\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 13:24\r
+ */\r
+public class PackageDependenciesStoreTest extends BaseTestCase {\r
+  private PackageDependenciesStore store;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    store = new PackageDependenciesStore();\r
+  }\r
+\r
+  @Test\r
+  public void test_load() throws IOException {\r
+    File temp = createTempFile("<nuget-dependencies>\n" +\r
+            "  <packages>\n" +\r
+            "    <package id=\"id1\" version=\"v1\" />\n" +\r
+            "    <package id=\"id2\" version=\"v2\" />\n" +\r
+            "  </packages>\n" +\r
+            "  <sources>\n" +\r
+            "    <source>source1</source>\n" +\r
+            "    <source>source2</source>\n" +\r
+            "  </sources>\n" +\r
+            "</nuget-dependencies>");\r
+\r
+    PackageDependencies deps = new PackageDependencies(Arrays.asList("source1", "source2"),\r
+            Arrays.asList(new PackageInfo("id1", "v1"), new PackageInfo("id2", "v2")));\r
+\r
+    PackageDependencies load = store.load(temp);\r
+    assertEquals(deps, load);\r
+  }\r
+\r
+\r
+  @Test\r
+  public void test_saveLoad() throws IOException {\r
+    final File tmp = createTempFile();\r
+\r
+    PackageDependencies deps = new PackageDependencies(Arrays.asList("source1", "source2"),\r
+            Arrays.asList(new PackageInfo("id1", "v1"), new PackageInfo("id2", "v2")));\r
+    store.save(deps, tmp);\r
+\r
+    dumpFile(tmp);\r
+\r
+    PackageDependencies load = store.load(tmp);\r
+\r
+    assertEquals(deps, load);\r
+  }\r
+\r
+  private void assertEquals(PackageDependencies deps, PackageDependencies load) {\r
+    Assert.assertEquals(new TreeSet<String>(load.getSources()), new TreeSet<String>(deps.getSources()));\r
+    Assert.assertEquals(new TreeSet<PackageInfo>(load.getPackages()), new TreeSet<PackageInfo>(deps.getPackages()));\r
+  }\r
+}\r
index 2d09ef25696594bd446d5c324e69f413e062491f..1b4d1883f1d5633e2f5c6f144325d76ee45ab57b 100644 (file)
@@ -9,6 +9,8 @@
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetUpdatePackageActionFactoryTest"/>\r
 \r
+      <class name="jetbrains.buildServer.nuget.tests.common.PackageDependenciesStoreTest"/>\r
+\r
       <class name="jetbrains.buildServer.nuget.tests.util.CompositeBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.util.DelegatingBuildProcessTest"/>\r
 \r