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.junit.jupiter.api.Test;
25
26
27
28
29 class SolrCliTest {
30
31 public static final String ZK_HOST = "localhost:9983";
32
33 public static final String DEFAULT_CONFIG_SET = "_default";
34
35 public static final Option OPTION_ZKHOST_DEPRECATED =
36
37 Option.builder("zkHost")
38 .longOpt("zkHost")
39 .deprecated(
40 DeprecatedAttributes.builder()
41 .setForRemoval(true)
42 .setSince("9.6")
43 .setDescription("Use --zk-host instead")
44 .get())
45 .argName("HOST")
46 .hasArg()
47 .required(false)
48 .desc("Zookeeper connection string; unnecessary if ZK_HOST is defined in solr.in.sh; otherwise, defaults to "
49 + ZK_HOST
50 + '.')
51 .build();
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 + '.')
64 .build();
65
66
67 public static final Option OPTION_SOLRURL_DEPRECATED =
68
69 Option.builder("solrUrl")
70 .longOpt("solrUrl")
71 .deprecated(
72 DeprecatedAttributes.builder()
73 .setForRemoval(true)
74 .setSince("9.6")
75 .setDescription("Use --solr-url instead")
76 .get())
77 .argName("HOST")
78 .hasArg()
79 .required(false)
80 .desc("Base Solr URL, which can be used to determine the zk-host if that's not known; defaults to: "
81 + getDefaultSolrUrl()
82 + '.')
83 .build();
84
85
86 public static final Option OPTION_SOLRURL =
87
88 Option.builder("url")
89 .longOpt("solr-url")
90 .argName("HOST")
91 .hasArg()
92 .required(false)
93 .desc("Base Solr URL, which can be used to determine the zk-host if that's not known; defaults to: "
94 + getDefaultSolrUrl()
95 + '.')
96 .build();
97
98
99 public static final Option OPTION_VERBOSE =
100
101 Option.builder("v")
102 .longOpt("verbose")
103 .argName("verbose")
104 .required(false)
105 .desc("Enable more verbose command output.")
106 .build();
107
108
109 public static final Option OPTION_HELP =
110
111 Option.builder("h")
112 .longOpt("help")
113 .required(false)
114 .desc("Print this message.")
115 .build();
116
117
118 public static final Option OPTION_RECURSE =
119
120 Option.builder("r")
121 .longOpt("recurse")
122 .argName("recurse")
123 .hasArg()
124 .required(false)
125 .desc("Recurse (true|false), default is false.")
126 .build();
127
128
129 public static final Option OPTION_CREDENTIALS =
130
131 Option.builder("u")
132 .longOpt("credentials")
133 .argName("credentials")
134 .hasArg()
135 .required(false)
136 .desc("Credentials in the format username:password. Example: --credentials solr:SolrRocks")
137 .build();
138
139
140 public static String getDefaultSolrUrl() {
141 final String scheme = "http";
142 final String host = "localhost";
143 final String port = "8983";
144 return String.format(Locale.ROOT, "%s://%s:%s", scheme.toLowerCase(Locale.ROOT), host, port);
145 }
146
147 @Test
148 public void testOptions() {
149
150 assertNotNull(DEFAULT_CONFIG_SET);
151 assertNotNull(OPTION_CREDENTIALS);
152 assertNotNull(OPTION_HELP);
153 assertNotNull(OPTION_RECURSE);
154 assertNotNull(OPTION_SOLRURL);
155 assertNotNull(OPTION_SOLRURL_DEPRECATED);
156 assertNotNull(OPTION_VERBOSE);
157 assertNotNull(OPTION_ZKHOST);
158 assertNotNull(OPTION_ZKHOST_DEPRECATED);
159 assertNotNull(ZK_HOST);
160 assertNotNull(getDefaultSolrUrl());
161 }
162 }