ImmutableConnection implements Connection { public static ConnectionBuilder getBuilder(final ConnectionId id, final ConnectionType connectionType, final ConnectivityStatus connectionStatus, final String uri) { return new Builder(connectionType) .id(id) .connectionStatus(connectionStatus) .uri(uri); } private  ImmutableConnection(final Builder builder); static ConnectionBuilder getBuilder(final ConnectionId id,
            final ConnectionType connectionType,
            final ConnectivityStatus connectionStatus,
            final String uri); static ConnectionBuilder getBuilder(final Connection connection); static Connection fromJson(final JsonObject jsonObject); @Override ConnectionId getId(); @Override Optional<String> getName(); @Override ConnectionType getConnectionType(); @Override ConnectivityStatus getConnectionStatus(); @Override List<Source> getSources(); @Override List<Target> getTargets(); @Override int getClientCount(); @Override boolean isFailoverEnabled(); @Override Optional<Credentials> getCredentials(); @Override Optional<String> getTrustedCertificates(); @Override String getUri(); @Override String getProtocol(); @Override Optional<String> getUsername(); @Override Optional<String> getPassword(); @Override String getHostname(); @Override int getPort(); @Override Optional<String> getPath(); @Override boolean isValidateCertificates(); @Override int getProcessorPoolSize(); @Override Map<String, String> getSpecificConfig(); @Override PayloadMappingDefinition getPayloadMappingDefinition(); @Override Set<String> getTags(); @Override Optional<ConnectionLifecycle> getLifecycle(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @SuppressWarnings("OverlyComplexMethod") @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void getBuilderFromConnectionCoversAllFields() { final Connection connection = ImmutableConnection.getBuilder(ID, TYPE, STATUS, URI) .sources(SOURCES) .targets(TARGETS) .connectionStatus(ConnectivityStatus.OPEN) .name("connection") .clientCount(5) .tag("AAA") .trustedCertificates("certs") .processorPoolSize(8) .credentials(ClientCertificateCredentials.newBuilder() .clientKey("clientkey") .clientCertificate("certificate") .build()) .validateCertificate(true) .uri("amqps: .id(ID) .payloadMappingDefinition( ConnectivityModelFactory.newPayloadMappingDefinition("test", KNOWN_JAVA_MAPPING_CONTEXT)) .build(); assertThat(ImmutableConnection.getBuilder(connection).build()).isEqualTo(connection); }
@Test public void createInstanceWithNullSources() { final ConnectionBuilder builder = ImmutableConnection.getBuilder(ID, TYPE, STATUS, URI); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> builder.sources(null)) .withMessage("The %s must not be null!", "sources") .withNoCause(); }
@Test public void createInstanceWithNullEventTarget() { final ConnectionBuilder builder = ImmutableConnection.getBuilder(ID, TYPE, STATUS, URI); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> builder.targets(null)) .withMessage("The %s must not be null!", "targets") .withNoCause(); }
@Test public void createInstanceWithoutSourceAndEventTarget() { final ConnectionBuilder builder = ImmutableConnection.getBuilder(ID, TYPE, STATUS, URI); assertThatExceptionOfType(ConnectionConfigurationInvalidException.class) .isThrownBy(builder::build) .withMessageContaining("source") .withMessageContaining("target") .withNoCause(); }