@Test public void mergeWithDefaultRoute() { doLoad().map(routes -> { final Routes.Route route = routes.routes.iterator().next(); assertEquals(route.clientConfiguration.executor.core.intValue(), 1); assertEquals(route.clientConfiguration.timeouts.read.longValue(), 6789); assertEquals(route.clientConfiguration.timeouts.connect.longValue(), 1235); return routes; }).orElseThrow(AssertionError::new); }
protected Optional<Routes> doLoad(final String content) { try (final Jsonb jsonb = JsonbBuilder.newBuilder() .withProvider(loadJsonpProvider()) .withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)) .build()) { routes = jsonb.fromJson(content, Routes.class); final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty(); if (routes.defaultRoute == null && !hasRoutes) { return Optional.empty(); } if (hasRoutes) { routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId()); } if (routes.defaultRoute != null) { if (routes.defaultRoute.id == null) { routes.defaultRoute.id = "default"; } if (routes.routes == null) { routes.routes = singletonList(routes.defaultRoute); } if (hasRoutes) { final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap()); final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class); routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList()); } } } catch (final Exception e) { throw new IllegalArgumentException(e); } routes.routes.forEach(this::init); return Optional.of(routes); }
ConfigurationLoader { protected Optional<Routes> doLoad(final String content) { try (final Jsonb jsonb = JsonbBuilder.newBuilder() .withProvider(loadJsonpProvider()) .withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)) .build()) { routes = jsonb.fromJson(content, Routes.class); final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty(); if (routes.defaultRoute == null && !hasRoutes) { return Optional.empty(); } if (hasRoutes) { routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId()); } if (routes.defaultRoute != null) { if (routes.defaultRoute.id == null) { routes.defaultRoute.id = "default"; } if (routes.routes == null) { routes.routes = singletonList(routes.defaultRoute); } if (hasRoutes) { final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap()); final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class); routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList()); } } } catch (final Exception e) { throw new IllegalArgumentException(e); } routes.routes.forEach(this::init); return Optional.of(routes); } }
ConfigurationLoader { protected Optional<Routes> doLoad(final String content) { try (final Jsonb jsonb = JsonbBuilder.newBuilder() .withProvider(loadJsonpProvider()) .withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)) .build()) { routes = jsonb.fromJson(content, Routes.class); final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty(); if (routes.defaultRoute == null && !hasRoutes) { return Optional.empty(); } if (hasRoutes) { routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId()); } if (routes.defaultRoute != null) { if (routes.defaultRoute.id == null) { routes.defaultRoute.id = "default"; } if (routes.routes == null) { routes.routes = singletonList(routes.defaultRoute); } if (hasRoutes) { final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap()); final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class); routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList()); } } } catch (final Exception e) { throw new IllegalArgumentException(e); } routes.routes.forEach(this::init); return Optional.of(routes); } ConfigurationLoader(final String path); }
ConfigurationLoader { protected Optional<Routes> doLoad(final String content) { try (final Jsonb jsonb = JsonbBuilder.newBuilder() .withProvider(loadJsonpProvider()) .withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)) .build()) { routes = jsonb.fromJson(content, Routes.class); final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty(); if (routes.defaultRoute == null && !hasRoutes) { return Optional.empty(); } if (hasRoutes) { routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId()); } if (routes.defaultRoute != null) { if (routes.defaultRoute.id == null) { routes.defaultRoute.id = "default"; } if (routes.routes == null) { routes.routes = singletonList(routes.defaultRoute); } if (hasRoutes) { final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap()); final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class); routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList()); } } } catch (final Exception e) { throw new IllegalArgumentException(e); } routes.routes.forEach(this::init); return Optional.of(routes); } ConfigurationLoader(final String path); Optional<Routes> load(); }
ConfigurationLoader { protected Optional<Routes> doLoad(final String content) { try (final Jsonb jsonb = JsonbBuilder.newBuilder() .withProvider(loadJsonpProvider()) .withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)) .build()) { routes = jsonb.fromJson(content, Routes.class); final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty(); if (routes.defaultRoute == null && !hasRoutes) { return Optional.empty(); } if (hasRoutes) { routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId()); } if (routes.defaultRoute != null) { if (routes.defaultRoute.id == null) { routes.defaultRoute.id = "default"; } if (routes.routes == null) { routes.routes = singletonList(routes.defaultRoute); } if (hasRoutes) { final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap()); final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class); routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList()); } } } catch (final Exception e) { throw new IllegalArgumentException(e); } routes.routes.forEach(this::init); return Optional.of(routes); } ConfigurationLoader(final String path); Optional<Routes> load();  }