@Test public void testChainOverridesProperties() throws NoSuchAlgorithmException { Properties props = new Properties(); props.setProperty(Options.PROP_TOKEN, "token"); props.setProperty(Options.PROP_CONNECTION_NAME, "name"); Options o = new Options.Builder(props).connectionName("newname").build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertEquals("property token", "token", o.getToken()); assertEquals("property connection name", "newname", o.getConnectionName()); }
io.nats.client.Connection createNatsConnection() throws IOException, InterruptedException { io.nats.client.Connection nc = null; if (getNatsConnection() == null) { if (opts.getNatsUrl() != null) { io.nats.client.Options natsOpts = new io.nats.client.Options.Builder(). connectionName(clientId). errorListener(opts.getErrorListener()). connectionListener(opts.getConnectionListener()). server(opts.getNatsUrl()). build(); nc = Nats.connect(natsOpts); } else { nc = Nats.connect(); } ncOwned = true; } return nc; }
io.nats.client.Connection createNatsConnection() throws IOException, InterruptedException { io.nats.client.Connection nc = null; if (getNatsConnection() == null) { if (opts.getNatsUrl() != null) { io.nats.client.Options natsOpts = new io.nats.client.Options.Builder(). connectionName(clientId). errorListener(opts.getErrorListener()). connectionListener(opts.getConnectionListener()). server(opts.getNatsUrl()). build(); nc = Nats.connect(natsOpts); } else { nc = Nats.connect(); } ncOwned = true; } return nc; }
@Test public void testConnectOptionsWithNameAndContext() throws Exception { SSLContext ctx = TestSSLUtils.createTestSSLContext(); Options o = new Options.Builder().sslContext(ctx).connectionName("c1").build(); String expected = "{\"lang\":\"java\",\"version\":\"" + Nats.CLIENT_VERSION + "\",\"name\":\"c1\"" + ",\"protocol\":1,\"verbose\":false,\"pedantic\":false,\"tls_required\":true,\"echo\":true}"; assertEquals("default connect options", expected, o.buildProtocolConnectOptionsString("nats://localhost:4222", false, null)); }
@Test public void testChainedStringOptions() throws NoSuchAlgorithmException { Options o = new Options.Builder().userInfo("hello", "world").connectionName("name").build(); assertEquals("default verbose", false, o.isVerbose()); // One from a different type assertEquals("chained username", "hello", o.getUsername()); assertEquals("chained password", "world", o.getPassword()); assertEquals("chained connection name", "name", o.getConnectionName()); }