aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2018-09-17 11:48:48 -0700
committerIvan Frade <ifrade@google.com>2018-10-12 13:59:06 -0700
commit6aca8899a5c02b3f6be7b9196cf5e935914476f0 (patch)
treebec623c7251d03297684721771d131434815cd30 /org.eclipse.jgit.test/tst
parentb3adaf7741094c30f77ea933e7faa3977291d870 (diff)
downloadjgit-6aca8899a5c02b3f6be7b9196cf5e935914476f0.tar.gz
jgit-6aca8899a5c02b3f6be7b9196cf5e935914476f0.zip
Move first line parsing for v0/v1 pack negotiation out of UploadPack
In protocol v0/v1 pack negotiation, the first want line contains the options the client wants in effect. This parsing is done in UploadPack but it doesn't have any interaction with that class. Move the code to its own class and package, mark the current one as deprecated (it is public API) and add unit tests. Take the chance to move the parsing code from the constructor to a factory method, making the class a simple container of results. Change-Id: I1757f535dda78a4111a1c12c3a3b455a4b6f0c51 Signed-off-by: Ivan Frade <ifrade@google.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/parser/FirstWantTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/parser/FirstWantTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/parser/FirstWantTest.java
new file mode 100644
index 0000000000..572ec8bae5
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/parser/FirstWantTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.internal.transport.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class FirstWantTest {
+
+ @Test
+ public void testFirstWantWithOptions() {
+ String line = "want b9d4d1eb2f93058814480eae9e1b67550f46ee38 "
+ + "no-progress include-tag ofs-delta agent=JGit/unknown";
+
+ FirstWant r = FirstWant.fromLine(line);
+ assertEquals("want b9d4d1eb2f93058814480eae9e1b67550f46ee38",
+ r.getLine());
+ Set<String> capabilities = r.getCapabilities();
+ Set<String> expectedCapabilities = new HashSet<>(
+ Arrays.asList("no-progress", "include-tag", "ofs-delta",
+ "agent=JGit/unknown"));
+ assertEquals(expectedCapabilities, capabilities);
+ }
+
+ @Test
+ public void testFirstWantWithoutOptions() {
+ String line = "want b9d4d1eb2f93058814480eae9e1b67550f46ee38";
+
+ FirstWant r = FirstWant.fromLine(line);
+ assertEquals("want b9d4d1eb2f93058814480eae9e1b67550f46ee38",
+ r.getLine());
+ assertTrue(r.getCapabilities().isEmpty());
+ }
+}