@Test public void testInvalidIpAddress() throws Exception { node.getAttributes().put("host", "256.256.256.256"); node.getAttributes().put("port", "1"); final HostAndPort plugin = buildPlugin(); assertNull("Expected null, but got: " + plugin, plugin); }
@Test public void testLocalhost() throws Exception { node.getAttributes().put("host", "localhost"); node.getAttributes().put("port", "1"); final HostAndPort hostAndPort = buildPlugin(); assertNotNull(hostAndPort); assertTrue(hostAndPort.isValid()); }
@Test public void testNegativePort() throws Exception { node.getAttributes().put("port", "-1"); assertNull(buildPlugin()); }
@Test public void testInvalidPort() throws Exception { node.getAttributes().put("port", "1234567890"); assertNull(buildPlugin()); }
@Test public void testValidPort() throws Exception { node.getAttributes().put("port", "10"); assertNotNull(buildPlugin()); }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("thing", "thing1"); node.getAttributes().put("foo1", "foo1"); final PluginWithGenericSubclassFoo1Builder validatingPlugin = (PluginWithGenericSubclassFoo1Builder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("thing1", validatingPlugin.getThing()); assertEquals("foo1", validatingPlugin.getFoo1()); } }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort"); assertNotNull("Rebuild this module to ensure annotation processing has been done.", plugin); node = new Node(null, "HostAndPort", plugin); node.getAttributes().put("host", "localhost"); }
Node queryIdAppenderNode = new Node(queryIdRouteNode, "test-query-file-appender", queryIdAppenderType); queryIdAppenderNode.getAttributes().put("fileName", logLocation + "/${ctx:sessionId}/${ctx:queryId}.test"); queryIdAppenderNode.getAttributes().put("name", "test-query-file-appender"); new PluginType<>(layoutEntry, PatternLayout.class, ""); Node layoutNode = new Node(queryIdAppenderNode, "PatternLayout", layoutType); layoutNode.getAttributes().put("pattern", LogDivertAppender.nonVerboseLayout);
PluginType<HushableRandomAccessFileAppender> childType = new PluginType<>(childEntry, HushableRandomAccessFileAppender.class, "appender"); Node childNode = new Node(node, "HushableMutableRandomAccess", childType); childNode.getAttributes().put("name", "query-file-appender"); childNode.getAttributes().put("fileName", logLocation + "/${ctx:sessionId}/${ctx:queryId}"); node.getChildren().add(childNode); PluginType<NameFilter> filterType = new PluginType<>(filterEntry, NameFilter.class, "filter"); Node filterNode = new Node(childNode, "NameFilter", filterType); filterNode.getAttributes().put("loggingLevel", loggingMode.name()); childNode.getChildren().add(filterNode); PluginType<PatternLayout> layoutType = new PluginType<>(layoutEntry, PatternLayout.class, "layout"); Node layoutNode = new Node(childNode, "PatternLayout", layoutType); layoutNode.getAttributes().put("pattern", layout); childNode.getChildren().add(layoutNode);
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); final ValidatingPlugin validatingPlugin = (ValidatingPlugin) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); } }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); final ValidatingPluginWithGenericBuilder validatingPlugin = (ValidatingPluginWithGenericBuilder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); } }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); // @formatter:off final ValidatingPluginWithTypedBuilder validatingPlugin = (ValidatingPluginWithTypedBuilder) new PluginBuilder(plugin). withConfiguration(new NullConfiguration()). withConfigurationNode(node).build(); // @formatter:on assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); } }
private boolean isSameReference(final Node node1, final Node node2) { final String value = node1.getAttributes().get(REF); return value != null && value.toLowerCase().equals(node2.getAttributes().get(REF).toLowerCase()); } }
private boolean isSameName(final Node node1, final Node node2) { final String value = node1.getAttributes().get(NAME); return value != null && value.toLowerCase().equals(node2.getAttributes().get(NAME).toLowerCase()); }
private Node getLoggerNode(final Node parentNode, final String name) { for (final Node node : parentNode.getChildren()) { final String nodeName = node.getAttributes().get(NAME); if (name == null && nodeName == null) { return node; } if (nodeName != null && nodeName.equals(name)) { return node; } } return null; }
private void processAttributes(final Node parent, final JsonNode node) { final Map<String, String> attrs = parent.getAttributes(); final Iterator<Map.Entry<String, JsonNode>> iter = node.fields(); while (iter.hasNext()) { final Map.Entry<String, JsonNode> entry = iter.next(); if (!entry.getKey().equalsIgnoreCase("type")) { final JsonNode n = entry.getValue(); if (n.isValueNode()) { attrs.put(entry.getKey(), n.asText()); } } } }
private void printNodes(final String indent, final Node node, final StringBuilder sb) { sb.append(indent).append(node.getName()).append(" type: ").append(node.getType()).append("\n"); sb.append(indent).append(node.getAttributes().toString()).append("\n"); for (final Node child : node.getChildren()) { printNodes(indent + " ", child, sb); } } }
public Node(final Node node) { this.parent = node.parent; this.name = node.name; this.type = node.type; this.attributes.putAll(node.getAttributes()); this.value = node.getValue(); for (final Node child : node.getChildren()) { this.children.add(new Node(child)); } this.object = node.object; }
@Override public Object visit(final Configuration configuration, final Node node, final LogEvent event, final StringBuilder log) { final String name = this.annotation.value(); final Map<String, String> attributes = node.getAttributes(); final String rawValue = removeAttributeValue(attributes, name, this.aliases); final String replacedValue = this.substitutor.replace(event, rawValue); final Object defaultValue = findDefaultValue(event); final Object value = convert(replacedValue, defaultValue); final Object debugValue = this.annotation.sensitive() ? NameUtil.md5(value + this.getClass().getName()) : value; StringBuilders.appendKeyDqValue(log, name, debugValue); return value; }
protected Node convertToNode(final Node parent, final Component component) { final String name = component.getPluginType(); final PluginType<?> pluginType = pluginManager.getPluginType(name); final Node node = new Node(parent, name, pluginType); node.getAttributes().putAll(component.getAttributes()); node.setValue(component.getValue()); final List<Node> children = node.getChildren(); for (final Component child : component.getComponents()) { children.add(convertToNode(node, child)); } return node; } }