@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); }
/** * Creates a new {@code Connection} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Connection to be created. * @return a new Connection which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Connection fromJson(final JsonObject jsonObject) { final ConnectionType type = getConnectionTypeOrThrow(jsonObject); final ConnectionBuilder builder = new Builder(type) .id(jsonObject.getValueOrThrow(JsonFields.ID)) .connectionStatus(getConnectionStatusOrThrow(jsonObject)) .uri(jsonObject.getValueOrThrow(JsonFields.URI)) .sources(getSources(jsonObject, type)) .targets(getTargets(jsonObject, type)) .name(jsonObject.getValue(JsonFields.NAME).orElse(null)) .mappingContext(jsonObject.getValue(JsonFields.MAPPING_CONTEXT) .map(ConnectivityModelFactory::mappingContextFromJson) .orElse(null)) .specificConfig(getSpecificConfiguration(jsonObject)) .tags(getTags(jsonObject)); jsonObject.getValue(JsonFields.CREDENTIALS).ifPresent(builder::credentialsFromJson); jsonObject.getValue(JsonFields.CLIENT_COUNT).ifPresent(builder::clientCount); jsonObject.getValue(JsonFields.FAILOVER_ENABLED).ifPresent(builder::failoverEnabled); jsonObject.getValue(JsonFields.VALIDATE_CERTIFICATES).ifPresent(builder::validateCertificate); jsonObject.getValue(JsonFields.PROCESSOR_POOL_SIZE).ifPresent(builder::processorPoolSize); jsonObject.getValue(JsonFields.TRUSTED_CERTIFICATES).ifPresent(builder::trustedCertificates); return builder.build(); }
/** * Creates a new {@code Connection} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Connection to be created. * @return a new Connection which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Connection fromJson(final JsonObject jsonObject) { final ConnectionType type = getConnectionTypeOrThrow(jsonObject); final ConnectionBuilder builder = new Builder(type) .id(jsonObject.getValueOrThrow(JsonFields.ID)) .connectionStatus(getConnectionStatusOrThrow(jsonObject)) .uri(jsonObject.getValueOrThrow(JsonFields.URI)) .sources(getSources(jsonObject, type)) .targets(getTargets(jsonObject, type)) .name(jsonObject.getValue(JsonFields.NAME).orElse(null)) .mappingContext(jsonObject.getValue(JsonFields.MAPPING_CONTEXT) .map(ConnectivityModelFactory::mappingContextFromJson) .orElse(null)) .specificConfig(getSpecificConfiguration(jsonObject)) .tags(getTags(jsonObject)); jsonObject.getValue(JsonFields.CREDENTIALS).ifPresent(builder::credentialsFromJson); jsonObject.getValue(JsonFields.CLIENT_COUNT).ifPresent(builder::clientCount); jsonObject.getValue(JsonFields.FAILOVER_ENABLED).ifPresent(builder::failoverEnabled); jsonObject.getValue(JsonFields.VALIDATE_CERTIFICATES).ifPresent(builder::validateCertificate); jsonObject.getValue(JsonFields.PROCESSOR_POOL_SIZE).ifPresent(builder::processorPoolSize); jsonObject.getValue(JsonFields.TRUSTED_CERTIFICATES).ifPresent(builder::trustedCertificates); return builder.build(); }
@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); }
@Test public void getBuilderFromConnectionCoversAllFields() { final Connection connection = ImmutableConnection.getBuilder(ID, TYPE, STATUS, URI) .sources(SOURCES) .targets(TARGETS) .connectionStatus(ConnectionStatus.OPEN) .name("connection") .clientCount(5) .tag("AAA") .trustedCertificates("certs") .processorPoolSize(8) .credentials(ClientCertificateCredentials.newBuilder() .clientKey("clientkey") .clientCertificate("certificate") .build()) .validateCertificate(true) .uri("amqps://some.amqp.org:5672") .id("id") .build(); assertThat(ImmutableConnection.getBuilder(connection).build()).isEqualTo(connection); }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.CLOSED).build());
restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.CLOSED).build());
.match(ConnectionModified.class, event -> restoreConnection(event.getConnection())) .match(ConnectionOpened.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.OPEN).build() : null)) .match(ConnectionClosed.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.CLOSED).build() : null)) .match(ConnectionDeleted.class, event -> restoreConnection(null)) .match(RecoveryCompleted.class, rc -> {
.match(ConnectionModified.class, event -> restoreConnection(event.getConnection())) .match(ConnectionOpened.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.OPEN).build() : null)) .match(ConnectionClosed.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.CLOSED).build() : null)) .match(ConnectionDeleted.class, event -> restoreConnection(null)) .match(RecoveryCompleted.class, rc -> {