+ @Test
+ void whenDmaapConfigHasSeveralStreamsPublishing() throws Exception {
+ JsonObject jsonRootObject = getJsonRootObject();
+ JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_publishes");
+ JsonObject fake_info_object = new JsonObject();
+ fake_info_object.addProperty("fake_info", "fake");
+ json.add("fake_info_object", new Gson().toJsonTree(fake_info_object));
+ DataPublishing data = new Gson().fromJson(json.toString(), DataPublishing.class);
+ final String expectedMessage =
+ "Invalid configuration. Number of streams must be one, config: " + data.toString();
+
+ Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject));
+
+ assertEquals(expectedMessage, actualException.getMessage(),
+ "Wrong error message when the DMaaP config has several streams publishing");
+ }
+
+ class DataPublishing {
+ private JsonObject dmaap_publisher;
+ private JsonObject fake_info_object;
+
+ @Override
+ public String toString() {
+ return String.format("[dmaap_publisher=%s, fake_info_object=%s]", dmaap_publisher.toString(),
+ fake_info_object.toString());
+ }
+ }
+
+ @Test
+ void whenDmaapConfigHasSeveralStreamsSubscribing() throws Exception {
+ JsonObject jsonRootObject = getJsonRootObject();
+ JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_subscribes");
+ JsonObject fake_info_object = new JsonObject();
+ fake_info_object.addProperty("fake_info", "fake");
+ json.add("fake_info_object", new Gson().toJsonTree(fake_info_object));
+ DataSubscribing data = new Gson().fromJson(json.toString(), DataSubscribing.class);
+ final String expectedMessage =
+ "Invalid configuration. Number of streams must be one, config: " + data.toString();
+
+ Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject));
+
+ assertEquals(expectedMessage, actualException.getMessage(),
+ "Wrong error message when the DMaaP config has several streams subscribing");
+ }
+
+ private class DataSubscribing {
+ private JsonObject dmaap_subscriber;
+ private JsonObject fake_info_object;
+
+ @Override
+ public String toString() {
+ return String.format("[dmaap_subscriber=%s, fake_info_object=%s]", dmaap_subscriber.toString(),
+ fake_info_object.toString());
+ }
+ }
+
+ @Test
+ void whenWrongMemberNameInObject() throws Exception {
+ JsonObject jsonRootObject = getJsonRootObject();
+ JsonObject json = jsonRootObject.getAsJsonObject("config");
+ json.remove("ric");
+ final String message = "Could not find member: 'ric' in: " + json;
+
+ Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject));
+
+ assertEquals(message, actualException.getMessage(), "Wrong error message when wrong member name in object");
+ }
+
+ JsonObject getDmaapInfo(JsonObject jsonRootObject, String streamsPublishesOrSubscribes,
+ String dmaapPublisherOrSubscriber) throws Exception {
+ return jsonRootObject.getAsJsonObject("config").getAsJsonObject(streamsPublishesOrSubscribes)
+ .getAsJsonObject(dmaapPublisherOrSubscriber).getAsJsonObject("dmaap_info");
+ }