/** * Returns a mutable builder with a fluent API for immutable {@code Connection}. The builder is initialised with the * entries of this instance. * * @return the new builder. */ default ConnectionBuilder toBuilder() { return ConnectivityModelFactory.newConnectionBuilder(this); }
/** * Returns a mutable builder with a fluent API for immutable {@code Connection}. The builder is initialised with the * entries of this instance. * * @return the new builder. */ default ConnectionBuilder toBuilder() { return ConnectivityModelFactory.newConnectionBuilder(this); }
@Test public void toStringDoesNotContainPassword() { final String password = "thePassword"; final String uri = "amqps://foo:" + password + "@host.com:5671"; final Connection connection = ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, uri) .sources(Collections.singletonList(SOURCE1)) .build(); assertThat(connection.toString()).doesNotContain(password); }
@Test public void createMinimalConnectionConfigurationInstance() { final Connection connection = ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, URI) .sources(SOURCES) .targets(TARGETS) .build(); assertThat(connection.getId()).isEqualTo(ID); assertThat((Object) connection.getConnectionType()).isEqualTo(TYPE); assertThat(connection.getUri()).isEqualTo(URI); assertThat(connection.getSources()).isEqualTo(SOURCES); }
@Test public void createInstanceWithNullUri() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, null)) .withMessage("The %s must not be null!", "URI") .withNoCause(); }
@Test public void createInstanceWithNullId() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> ConnectivityModelFactory.newConnectionBuilder(null, TYPE, STATUS, URI)) .withMessage("The %s must not be null!", "ID") .withNoCause(); }
@Test public void fromJsonReturnsExpected() { final Connection expected = ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, URI) .credentials(CREDENTIALS) .name(NAME) .sources(SOURCES) .targets(TARGETS) .clientCount(2) .mappingContext(KNOWN_MAPPING_CONTEXT) .tags(KNOWN_TAGS) .build(); final Connection actual = ImmutableConnection.fromJson(KNOWN_JSON); assertThat(actual).isEqualTo(expected); }
@Test public void toJsonReturnsExpected() { final Connection underTest = ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, URI) .credentials(CREDENTIALS) .name(NAME) .sources(Arrays.asList(SOURCE2, SOURCE1)) // use different order to test sorting .targets(TARGETS) .clientCount(2) .mappingContext(KNOWN_MAPPING_CONTEXT) .tags(KNOWN_TAGS) .build(); final JsonObject actual = underTest.toJson(); assertThat(actual).isEqualTo(KNOWN_JSON); }