|
| 1 | +// SPDX-License-Identifier: MPL-2.0 |
| 2 | +// SPDX-FileCopyrightText: 2025 Mitch Gaffigan |
| 3 | + |
| 4 | +package com.mirth.connect.client.ui; |
| 5 | + |
| 6 | +import static org.junit.Assert.assertEquals; |
| 7 | + |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +public class CommandLineOptionsTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + public void testParseSslForm() { |
| 14 | + String[] args = new String[] { "https://example:8443", "1.0", "-ssl", "TLSv1.2,TLSv1.3", "TLS_RSA_WITH_AES_128_GCM_SHA256", "alice", "secret" }; |
| 15 | + CommandLineOptions opts = new CommandLineOptions(args); |
| 16 | + |
| 17 | + assertEquals("https://example:8443", opts.getServer()); |
| 18 | + assertEquals("1.0", opts.getVersion()); |
| 19 | + assertEquals("alice", opts.getUsername()); |
| 20 | + assertEquals("secret", opts.getPassword()); |
| 21 | + assertEquals("TLSv1.2,TLSv1.3", opts.getProtocols()); |
| 22 | + assertEquals("TLS_RSA_WITH_AES_128_GCM_SHA256", opts.getCipherSuites()); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testParseUsernameFormWithSsl() { |
| 27 | + String[] args = new String[] { "https://example:8443", "1.0", "bob", "pw", "-ssl", "TLSv1.2", "CIPHER" }; |
| 28 | + CommandLineOptions opts = new CommandLineOptions(args); |
| 29 | + |
| 30 | + assertEquals("https://example:8443", opts.getServer()); |
| 31 | + assertEquals("1.0", opts.getVersion()); |
| 32 | + assertEquals("bob", opts.getUsername()); |
| 33 | + assertEquals("pw", opts.getPassword()); |
| 34 | + assertEquals("TLSv1.2", opts.getProtocols()); |
| 35 | + assertEquals("CIPHER", opts.getCipherSuites()); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testNullArgsUsesDefaults() { |
| 40 | + CommandLineOptions opts = new CommandLineOptions((String[]) null); |
| 41 | + |
| 42 | + assertEquals("https://localhost:8443", opts.getServer()); |
| 43 | + assertEquals("", opts.getVersion()); |
| 44 | + assertEquals("", opts.getUsername()); |
| 45 | + assertEquals("", opts.getPassword()); |
| 46 | + assertEquals("", opts.getProtocols()); |
| 47 | + assertEquals("", opts.getCipherSuites()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testNormal() { |
| 52 | + String[] args = new String[] { "https://example:8443", "1.0" }; |
| 53 | + CommandLineOptions opts = new CommandLineOptions(args); |
| 54 | + |
| 55 | + assertEquals("https://example:8443", opts.getServer()); |
| 56 | + assertEquals("1.0", opts.getVersion()); |
| 57 | + assertEquals("", opts.getUsername()); |
| 58 | + assertEquals("", opts.getPassword()); |
| 59 | + assertEquals("", opts.getProtocols()); |
| 60 | + assertEquals("", opts.getCipherSuites()); |
| 61 | + } |
| 62 | +} |
0 commit comments