VirtualCheckExpressionParser { public static final VirtualCheckOperator parseVirtualCheckExpression(String expression) { try { try (StringReader reader = new StringReader(expression)) { VirtualCheckExpressionParserInternal parser = new VirtualCheckExpressionParserInternal(reader); return parser.readExpression(); } } catch (Exception e) { throw new RuntimeException("Failed to parse virtual check expression: '" + expression + "'", e); } }  static final VirtualCheckOperator parseVirtualCheckExpression(String expression); static final List<CheckReference<?>> parseParentsExpression(String expression);  }
@Test public void testParseCase1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("case when host 'vm1' is OK then OK when host 'vm1' is WARNING then OK else CRITICAL end"); assertThat(op.toString(), is(equalTo("case when host 'vm1' is OK then OK when host 'vm1' is WARNING then OK else CRITICAL end"))); }
@Test public void testParseOneOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("one of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseTwoOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("two of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("two of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseThreeOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("three of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("three of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseFourOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("four of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("four of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseFiveOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("five of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("five of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseSixOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("six of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("six of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseSevenOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("seven of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("seven of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseEightOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("eight of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("eight of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseNineOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("nine of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING"); assertThat(op.toString(), is(equalTo("nine of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING"))); }
@Test public void testParseMajorityOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("majority of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING, CRITICAL"))); }
@Test public void testParseQuorumOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("quorum of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] as WARNING, CRITICAL"))); }
@Test public void testParseAnyOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("any of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ]"); assertThat(op.toString(), is(equalTo("any of [host 'vm1', host 'vm2', host 'vm3', host 'vm4']"))); }
@Test public void testParseAllOf1() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("all of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ]"); assertThat(op.toString(), is(equalTo("all of [host 'vm1', host 'vm2', host 'vm3', host 'vm4']"))); }
@Test public void testParseCountEQ() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count OK of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is == 1"); assertThat(op.toString(), is(equalTo("count OK of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is == 1 as CRITICAL"))); }
@Test public void testParseCountNE() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count WARNING of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is != 1"); assertThat(op.toString(), is(equalTo("count WARNING of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is != 1 as CRITICAL"))); }
@Test public void testParseCountLT() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is < 1"); assertThat(op.toString(), is(equalTo("count of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is < 1 as CRITICAL"))); }
@Test public void testParseCountLTEQ() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is <= 1"); assertThat(op.toString(), is(equalTo("count of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is <= 1 as CRITICAL"))); }
@Test public void testParseCountGT() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is > 1"); assertThat(op.toString(), is(equalTo("count of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is > 1 as CRITICAL"))); }
@Test public void testParseCountGTEQ() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count of [ host 'vm1', host 'vm2', host 'vm3', host 'vm4' ] is >= 1"); assertThat(op.toString(), is(equalTo("count of [host 'vm1', host 'vm2', host 'vm3', host 'vm4'] is >= 1 as CRITICAL"))); }
@Test public void testParseOneOfHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of hosts in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOfHostPoolAlt() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of hosts in resource pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseMajorityOfHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("majority of hosts in pool 'test' as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of hosts in pool 'test' as WARNING, CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseMajorityOfHostPoolAlt() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("majority of hosts in resource pool 'test' as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of hosts in pool 'test' as WARNING, CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseQuorumOfHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("quorum of hosts in pool 'test' as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of hosts in pool 'test' as WARNING, CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseQuorumOfHostPoolAlt() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("quorum of hosts in resource pool 'test' as WARNING, CRITICAL"); assertThat(op.toString(), is(equalTo("majority of hosts in pool 'test' as WARNING, CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOfAnonServicePool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of services in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of services in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOfAnonTrapPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of traps in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of traps in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOfServicePool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of service 'test' on hosts in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of service 'test' on hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOfTrapPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one of trap 'test' on hosts in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one of trap 'test' on hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseCountHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count hosts in pool 'test' > 1 as CRITICAL"); assertThat(op.toString(), is(equalTo("count of hosts in pool 'test' is > 1 as CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseCountServicePool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("count OK of service 'test' on hosts in pool 'test' >= 1 as CRITICAL"); assertThat(op.toString(), is(equalTo("count OK of service 'test' on hosts in pool 'test' is >= 1 as CRITICAL"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOrMoreOfHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one or more of hosts in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one or more of hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }
@Test public void testParseOneOrLessOfHostPool() { VirtualCheckOperator op = VirtualCheckExpressionParser.parseVirtualCheckExpression("one or less of hosts in pool 'test' as WARNING"); assertThat(op.toString(), is(equalTo("one or less of hosts in pool 'test' as WARNING"))); assertThat(op.computePoolDependencies(null), is(equalTo(new HashSet<String>(Arrays.asList("test"))))); }