1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.transport;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertTrue;
16
17 import org.eclipse.jgit.lib.Config;
18 import org.eclipse.jgit.transport.PushConfig.PushDefault;
19 import org.eclipse.jgit.transport.PushConfig.PushRecurseSubmodulesMode;
20 import org.junit.Test;
21
22 public class PushConfigTest {
23
24 @Test
25 public void pushRecurseSubmoduleMatch() throws Exception {
26 assertTrue(PushRecurseSubmodulesMode.CHECK.matchConfigValue("check"));
27 assertTrue(PushRecurseSubmodulesMode.CHECK.matchConfigValue("CHECK"));
28
29 assertTrue(PushRecurseSubmodulesMode.ON_DEMAND
30 .matchConfigValue("on-demand"));
31 assertTrue(PushRecurseSubmodulesMode.ON_DEMAND
32 .matchConfigValue("ON-DEMAND"));
33 assertTrue(PushRecurseSubmodulesMode.ON_DEMAND
34 .matchConfigValue("on_demand"));
35 assertTrue(PushRecurseSubmodulesMode.ON_DEMAND
36 .matchConfigValue("ON_DEMAND"));
37
38 assertTrue(PushRecurseSubmodulesMode.NO.matchConfigValue("no"));
39 assertTrue(PushRecurseSubmodulesMode.NO.matchConfigValue("NO"));
40 assertTrue(PushRecurseSubmodulesMode.NO.matchConfigValue("false"));
41 assertTrue(PushRecurseSubmodulesMode.NO.matchConfigValue("FALSE"));
42 }
43
44 @Test
45 public void pushRecurseSubmoduleNoMatch() throws Exception {
46 assertFalse(PushRecurseSubmodulesMode.NO.matchConfigValue("N"));
47 assertFalse(PushRecurseSubmodulesMode.ON_DEMAND
48 .matchConfigValue("ONDEMAND"));
49 }
50
51 @Test
52 public void pushRecurseSubmoduleToConfigValue() {
53 assertEquals("on-demand",
54 PushRecurseSubmodulesMode.ON_DEMAND.toConfigValue());
55 assertEquals("check", PushRecurseSubmodulesMode.CHECK.toConfigValue());
56 assertEquals("false", PushRecurseSubmodulesMode.NO.toConfigValue());
57 }
58
59 @Test
60 public void pushDefaultMatch() throws Exception {
61 assertTrue(PushDefault.NOTHING.matchConfigValue("nothing"));
62 assertTrue(PushDefault.NOTHING.matchConfigValue("NOTHING"));
63 assertTrue(PushDefault.CURRENT.matchConfigValue("current"));
64 assertTrue(PushDefault.CURRENT.matchConfigValue("CURRENT"));
65 assertTrue(PushDefault.UPSTREAM.matchConfigValue("upstream"));
66 assertTrue(PushDefault.UPSTREAM.matchConfigValue("UPSTREAM"));
67 assertTrue(PushDefault.UPSTREAM.matchConfigValue("tracking"));
68 assertTrue(PushDefault.UPSTREAM.matchConfigValue("TRACKING"));
69 assertTrue(PushDefault.SIMPLE.matchConfigValue("simple"));
70 assertTrue(PushDefault.SIMPLE.matchConfigValue("SIMPLE"));
71 assertTrue(PushDefault.MATCHING.matchConfigValue("matching"));
72 assertTrue(PushDefault.MATCHING.matchConfigValue("MATCHING"));
73 }
74
75 @Test
76 public void pushDefaultNoMatch() throws Exception {
77 assertFalse(PushDefault.NOTHING.matchConfigValue("n"));
78 assertFalse(PushDefault.CURRENT.matchConfigValue(""));
79 assertFalse(PushDefault.UPSTREAM.matchConfigValue("track"));
80 }
81
82 @Test
83 public void pushDefaultToConfigValue() throws Exception {
84 assertEquals("nothing", PushDefault.NOTHING.toConfigValue());
85 assertEquals("current", PushDefault.CURRENT.toConfigValue());
86 assertEquals("upstream", PushDefault.UPSTREAM.toConfigValue());
87 assertEquals("simple", PushDefault.SIMPLE.toConfigValue());
88 assertEquals("matching", PushDefault.MATCHING.toConfigValue());
89 }
90
91 @Test
92 public void testEmptyConfig() throws Exception {
93 PushConfig cfg = parse("");
94 assertEquals(PushRecurseSubmodulesMode.NO, cfg.getRecurseSubmodules());
95 assertEquals(PushDefault.SIMPLE, cfg.getPushDefault());
96 }
97
98 @Test
99 public void testConfig() throws Exception {
100 PushConfig cfg = parse(
101 "[push]\n\tdefault = tracking\n\trecurseSubmodules = on-demand\n");
102 assertEquals(PushRecurseSubmodulesMode.ON_DEMAND,
103 cfg.getRecurseSubmodules());
104 assertEquals(PushDefault.UPSTREAM, cfg.getPushDefault());
105 }
106
107 private static PushConfig parse(String content) throws Exception {
108 Config c = new Config();
109 c.fromText(content);
110 return c.get(PushConfig::new);
111 }
112
113 }