View Javadoc
1   /*
2    * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.transport;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNull;
14  import static org.junit.Assert.assertTrue;
15  import static org.junit.Assert.assertFalse;
16  
17  import org.eclipse.jgit.lib.Config;
18  import org.junit.Test;
19  
20  /**
21   * Tests for {@link TransferConfig} parsing.
22   */
23  public class TransferConfigTest {
24  
25  	@Test
26  	public void testParseProtocolV0() {
27  		Config rc = new Config();
28  		rc.setInt("protocol", null, "version", 0);
29  		TransferConfig tc = new TransferConfig(rc);
30  		assertEquals(TransferConfig.ProtocolVersion.V0, tc.protocolVersion);
31  	}
32  
33  	@Test
34  	public void testParseProtocolV1() {
35  		Config rc = new Config();
36  		rc.setInt("protocol", null, "version", 1);
37  		TransferConfig tc = new TransferConfig(rc);
38  		assertEquals(TransferConfig.ProtocolVersion.V0, tc.protocolVersion);
39  	}
40  
41  	@Test
42  	public void testParseProtocolV2() {
43  		Config rc = new Config();
44  		rc.setInt("protocol", null, "version", 2);
45  		TransferConfig tc = new TransferConfig(rc);
46  		assertEquals(TransferConfig.ProtocolVersion.V2, tc.protocolVersion);
47  	}
48  
49  	@Test
50  	public void testParseProtocolNotSet() {
51  		Config rc = new Config();
52  		TransferConfig tc = new TransferConfig(rc);
53  		assertNull(tc.protocolVersion);
54  	}
55  
56  	@Test
57  	public void testParseProtocolUnknown() {
58  		Config rc = new Config();
59  		rc.setInt("protocol", null, "version", 3);
60  		TransferConfig tc = new TransferConfig(rc);
61  		assertNull(tc.protocolVersion);
62  	}
63  
64  	@Test
65  	public void testParseProtocolInvalid() {
66  		Config rc = new Config();
67  		rc.setString("protocol", null, "version", "foo");
68  		TransferConfig tc = new TransferConfig(rc);
69  		assertNull(tc.protocolVersion);
70  	}
71  
72  	@Test
73  	public void testParseAdvertiseSIDDefault() {
74  		Config rc = new Config();
75  		TransferConfig tc = new TransferConfig(rc);
76  		assertFalse(tc.isAllowReceiveClientSID());
77  	}
78  
79  	@Test
80  	public void testParseAdvertiseSIDSet() {
81  		Config rc = new Config();
82  		rc.setBoolean("transfer", null, "advertiseSID", true);
83  		TransferConfig tc = new TransferConfig(rc);
84  		assertTrue(tc.isAllowReceiveClientSID());
85  	}
86  }