1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.cli;
19
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21
22 import java.util.Locale;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 class SolrCliTest {
31
32 public static final String ZK_HOST = "localhost:9983";
33
34 public static final String DEFAULT_CONFIG_SET = "_default";
35
36 public static final Option OPTION_ZKHOST_DEPRECATED =
37
38 Option.builder("zkHost")
39 .longOpt("zkHost")
40 .deprecated(
41 DeprecatedAttributes.builder()
42 .setForRemoval(true)
43 .setSince("9.6")
44 .setDescription("Use --zk-host instead")
45 .get())
46 .argName("HOST")
47 .hasArg()
48 .required(false)
49 .desc("Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh; otherwise, defaults to "
50 + ZK_HOST
51 + '.').get();
52
53
54 public static final Option OPTION_ZKHOST =
55
56 Option.builder("z")
57 .longOpt("zk-host")
58 .argName("HOST")
59 .hasArg()
60 .required(false)
61 .desc("Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh; otherwise, defaults to "
62 + ZK_HOST
63 + '.').get();
64
65
66 public static final Option OPTION_SOLRURL_DEPRECATED =
67
68 Option.builder("solrUrl")
69 .longOpt("solrUrl")
70 .deprecated(
71 DeprecatedAttributes.builder()
72 .setForRemoval(true)
73 .setSince("9.6")
74 .setDescription("Use --solr-url instead")
75 .get())
76 .argName("HOST")
77 .hasArg()
78 .required(false)
79 .desc("Base Solr URL, which can be used to determine the zk-host if that's not known; defaults to: "
80 + getDefaultSolrUrl()
81 + '.').get();
82
83
84 public static final Option OPTION_SOLRURL =
85
86 Option.builder("url")
87 .longOpt("solr-url")
88 .argName("HOST")
89 .hasArg()
90 .required(false)
91 .desc("Base Solr URL, which can be used to determine the zk-host if that's not known; defaults to: "
92 + getDefaultSolrUrl()
93 + '.').get();
94
95
96 public static final Option OPTION_VERBOSE =
97
98 Option.builder("v")
99 .longOpt("verbose")
100 .argName("verbose")
101 .required(false)
102 .desc("Enable more verbose command output.").get();
103
104
105 public static final Option OPTION_HELP =
106
107 Option.builder("h")
108 .longOpt("help")
109 .required(false)
110 .desc("Print this message.").get();
111
112
113 public static final Option OPTION_RECURSE =
114
115 Option.builder("r")
116 .longOpt("recurse")
117 .argName("recurse")
118 .hasArg()
119 .required(false)
120 .desc("Recurse (true|false), default is false.").get();
121
122
123 public static final Option OPTION_CREDENTIALS =
124
125 Option.builder("u")
126 .longOpt("credentials")
127 .argName("credentials")
128 .hasArg()
129 .required(false)
130 .desc("Credentials in the format username:password. Example: --credentials solr:SolrRocks").get();
131
132
133 private static String getDefaultSolrUrl() {
134 final String scheme = "http";
135 final String host = "localhost";
136 final String port = "8983";
137 return String.format(Locale.ROOT, "%s://%s:%s", StringUtils.toRootLowerCase(scheme), host, port);
138 }
139
140 @Test
141 void testOptions() {
142
143 assertNotNull(DEFAULT_CONFIG_SET);
144 assertNotNull(OPTION_CREDENTIALS);
145 assertNotNull(OPTION_HELP);
146 assertNotNull(OPTION_RECURSE);
147 assertNotNull(OPTION_SOLRURL);
148 assertNotNull(OPTION_SOLRURL_DEPRECATED);
149 assertNotNull(OPTION_VERBOSE);
150 assertNotNull(OPTION_ZKHOST);
151 assertNotNull(OPTION_ZKHOST_DEPRECATED);
152 assertNotNull(ZK_HOST);
153 assertNotNull(getDefaultSolrUrl());
154 }
155 }