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         http://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.junit.jupiter.api.Test;
25  
26  /**
27   * Test fixtures used in SOLR tests.
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      // @formatter:off
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      // @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                      + '.')
64              .build();
65      // @formatter:on
66  
67      public static final Option OPTION_SOLRURL_DEPRECATED =
68      // @formatter:off
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      // @formatter:on
85  
86      public static final Option OPTION_SOLRURL =
87      // @formatter:off
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      // @formatter:on
98  
99      public static final Option OPTION_VERBOSE =
100     // @formatter:off
101         Option.builder("v")
102             .longOpt("verbose")
103             .argName("verbose")
104             .required(false)
105             .desc("Enable more verbose command output.")
106             .build();
107     // @formatter:on
108 
109     public static final Option OPTION_HELP =
110     // @formatter:off
111         Option.builder("h")
112             .longOpt("help")
113             .required(false)
114             .desc("Print this message.")
115             .build();
116     // @formatter:on
117 
118     public static final Option OPTION_RECURSE =
119     // @formatter:off
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     // @formatter:on
128 
129     public static final Option OPTION_CREDENTIALS =
130     // @formatter:off
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     // @formatter:on
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         // sanity checks
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 }