VirtualCheckExpressionParser { public static final List<CheckReference<?>> parseParentsExpression(String expression) { try { try (StringReader reader = new StringReader(expression)) { VirtualCheckExpressionParserInternal parser = new VirtualCheckExpressionParserInternal(reader); return parser.readParents(); } } catch (Exception e) { throw new RuntimeException("Failed to parse parents expression: '" + expression + "'", e); } }  static final VirtualCheckOperator parseVirtualCheckExpression(String expression); static final List<CheckReference<?>> parseParentsExpression(String expression);  }
@Test public void testParseAnonymousServiceParent() { List<CheckReference<?>> refs = VirtualCheckExpressionParser.parseParentsExpression("service 'check_sshd'"); assertThat(refs, is(notNullValue())); assertThat(refs.size(), is(equalTo(1))); assertThat(refs.get(0), is(notNullValue())); assertThat(refs.get(0), is(instanceOf(AnonymousService.class))); assertThat(refs.get(0), is(hasProperty("name", equalTo("check_sshd")))); }
@Test public void testParseAnonymousTrapParent() { List<CheckReference<?>> refs = VirtualCheckExpressionParser.parseParentsExpression("trap 'port_e1/1'"); assertThat(refs, is(notNullValue())); assertThat(refs.size(), is(equalTo(1))); assertThat(refs.get(0), is(notNullValue())); assertThat(refs.get(0), is(instanceOf(AnonymousTrap.class))); assertThat(refs.get(0), is(hasProperty("name", equalTo("port_e1/1")))); }
@Test public void testParseAnonymousServiceAndTrapParent() { List<CheckReference<?>> refs = VirtualCheckExpressionParser.parseParentsExpression("service 'check_sshd', trap 'port_g1/48'"); assertThat(refs, is(notNullValue())); assertThat(refs.size(), is(equalTo(2))); assertThat(refs.get(0), is(notNullValue())); assertThat(refs.get(0), is(instanceOf(AnonymousService.class))); assertThat(refs.get(0), is(hasProperty("name", equalTo("check_sshd")))); assertThat(refs.get(1), is(notNullValue())); assertThat(refs.get(1), is(instanceOf(AnonymousTrap.class))); assertThat(refs.get(1), is(hasProperty("name", equalTo("port_g1/48")))); }
@Test public void testParseServiceAndAnonymousServiceParent() { List<CheckReference<?>> refs = VirtualCheckExpressionParser.parseParentsExpression("service 'ping', service 'ping' on host 'default_gateway', service 'ping'"); assertThat(refs, is(notNullValue())); assertThat(refs.size(), is(equalTo(3))); assertThat(refs.get(0), is(notNullValue())); assertThat(refs.get(0), is(instanceOf(AnonymousService.class))); assertThat(refs.get(0), is(hasProperty("name", equalTo("ping")))); assertThat(refs.get(1), is(notNullValue())); assertThat(refs.get(1), is(instanceOf(ServiceByName.class))); assertThat(refs.get(1), is(hasProperty("name", equalTo("ping")))); assertThat(refs.get(1), is(hasProperty("host", is(instanceOf(HostByName.class))))); assertThat(refs.get(1), is(hasProperty("host", hasProperty("name", equalTo("default_gateway"))))); assertThat(refs.get(2), is(notNullValue())); assertThat(refs.get(2), is(instanceOf(AnonymousService.class))); assertThat(refs.get(2), is(hasProperty("name", equalTo("ping")))); }
@Test public void testParseTrapAndAnonymousTrapParent() { List<CheckReference<?>> refs = VirtualCheckExpressionParser.parseParentsExpression("trap 'port_1', trap 'port_2' on host 'sw1', trap 'port_3'"); assertThat(refs, is(notNullValue())); assertThat(refs.size(), is(equalTo(3))); assertThat(refs.get(0), is(notNullValue())); assertThat(refs.get(0), is(instanceOf(AnonymousTrap.class))); assertThat(refs.get(0), is(hasProperty("name", equalTo("port_1")))); assertThat(refs.get(1), is(notNullValue())); assertThat(refs.get(1), is(instanceOf(TrapByName.class))); assertThat(refs.get(1), is(hasProperty("name", equalTo("port_2")))); assertThat(refs.get(1), is(hasProperty("host", is(instanceOf(HostByName.class))))); assertThat(refs.get(1), is(hasProperty("host", hasProperty("name", equalTo("sw1"))))); assertThat(refs.get(2), is(notNullValue())); assertThat(refs.get(2), is(instanceOf(AnonymousTrap.class))); assertThat(refs.get(2), is(hasProperty("name", equalTo("port_3")))); }