/** * 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 connectionFromJson(final JsonObject jsonObject) { return ImmutableConnection.fromJson(jsonObject); }
/** * 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 connectionFromJson(final JsonObject jsonObject) { return ImmutableConnection.fromJson(jsonObject); }
@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 fromInvalidJsonFails() { final JsonObject INVALID_JSON = KNOWN_JSON.remove(Connection.JsonFields.SOURCES.getPointer()) .remove(Connection.JsonFields.TARGETS.getPointer()); assertThatExceptionOfType(ConnectionConfigurationInvalidException.class) .isThrownBy(() -> ImmutableConnection.fromJson(INVALID_JSON)) .withMessageContaining("source") .withMessageContaining("target") .withNoCause(); }