View Javadoc
1   /*
2     Licensed to the Apache Software Foundation (ASF) under one or more
3     contributor license agreements.  See the NOTICE file distributed with
4     this work for additional information regarding copyright ownership.
5     The ASF licenses this file to You under the Apache License, Version 2.0
6     (the "License"); you may not use this file except in compliance with
7     the License.  You may obtain a copy of the License at
8   
9         https://www.apache.org/licenses/LICENSE-2.0
10  
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
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   * Test fixtures used in SOLR tests.
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      // @formatter:off
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      // @formatter:on
53  
54      public static final Option OPTION_ZKHOST =
55      // @formatter:off
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      // @formatter:on
65  
66      public static final Option OPTION_SOLRURL_DEPRECATED =
67      // @formatter:off
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      // @formatter:on
83  
84      public static final Option OPTION_SOLRURL =
85      // @formatter:off
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      // @formatter:on
95  
96      public static final Option OPTION_VERBOSE =
97      // @formatter:off
98          Option.builder("v")
99      .longOpt("verbose")
100     .argName("verbose")
101     .required(false)
102     .desc("Enable more verbose command output.").get();
103     // @formatter:on
104 
105     public static final Option OPTION_HELP =
106     // @formatter:off
107         Option.builder("h")
108     .longOpt("help")
109     .required(false)
110     .desc("Print this message.").get();
111     // @formatter:on
112 
113     public static final Option OPTION_RECURSE =
114     // @formatter:off
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     // @formatter:on
122 
123     public static final Option OPTION_CREDENTIALS =
124     // @formatter:off
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     // @formatter:on
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         // sanity checks
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 }