Author: ghenzler
Date: Sat Jan 5 00:20:45 2019
New Revision: 1850448
URL: http://svn.apache.org/viewvc?rev=1850448&view=rev
Log:
FELIX-6012 Moving JMX Attribute check to module generalchecks
Added:
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/JmxAttributeCheck.java
- copied, changed from r1850438,
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheck.java
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintChecker.java
- copied, changed from r1850438,
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/util/SimpleConstraintChecker.java
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/JmxAttributeHealthCheckTest.java
- copied, changed from r1850438,
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckTest.java
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintCheckerTest.java
- copied, changed from r1850438,
felix/trunk/healthcheck/api/src/test/java/org/apache/felix/hc/util/SimpleConstraintCheckerTest.java
Removed:
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/util/SimpleConstraintChecker.java
felix/trunk/healthcheck/api/src/test/java/org/apache/felix/hc/util/SimpleConstraintCheckerTest.java
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheck.java
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckConfiguration.java
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckTest.java
Modified:
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/jmx/impl/HealthCheckMBeanTest.java
felix/trunk/healthcheck/docs/felix-health-checks.md
Modified:
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/jmx/impl/HealthCheckMBeanTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/jmx/impl/HealthCheckMBeanTest.java?rev=1850448&r1=1850447&r2=1850448&view=diff
==============================================================================
---
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/jmx/impl/HealthCheckMBeanTest.java
(original)
+++
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/jmx/impl/HealthCheckMBeanTest.java
Sat Jan 5 00:20:45 2019
@@ -17,7 +17,9 @@
*/
package org.apache.felix.hc.jmx.impl;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.lang.management.ManagementFactory;
@@ -29,13 +31,11 @@ import javax.management.ObjectName;
import org.apache.felix.hc.api.HealthCheck;
import org.apache.felix.hc.api.Result;
-import org.apache.felix.hc.api.ResultLog;
import org.apache.felix.hc.api.execution.HealthCheckExecutionOptions;
import org.apache.felix.hc.api.execution.HealthCheckExecutionResult;
import org.apache.felix.hc.api.execution.HealthCheckSelector;
import org.apache.felix.hc.core.impl.executor.ExtendedHealthCheckExecutor;
import org.apache.felix.hc.util.HealthCheckMetadata;
-import org.apache.felix.hc.util.SimpleConstraintChecker;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
@@ -57,18 +57,14 @@ public class HealthCheckMBeanTest {
}
};
- private void assertJmxValue(String mbeanName, String attributeName, String
constraint, boolean expected) throws Exception {
+ private Object getJmxValue(String mbeanName, String attributeName) throws
Exception {
final MBeanServer jmxServer =
ManagementFactory.getPlatformMBeanServer();
final ObjectName objectName = new ObjectName(mbeanName);
if (jmxServer.queryNames(objectName, null).size() == 0) {
fail("MBean not found: " + objectName);
}
final Object value = jmxServer.getAttribute(objectName, attributeName);
- final ResultLog resultLog = new ResultLog();
- new SimpleConstraintChecker().check(value, constraint, resultLog);
- assertEquals("Expecting result " + expected + "(" + resultLog + ")",
expected,
- resultLog.getAggregateStatus().equals(Result.Status.OK));
-
+ return value;
}
@Test
@@ -152,14 +148,15 @@ public class HealthCheckMBeanTest {
jmxServer.registerMBean(mbean, name);
try {
resultOk = true;
- assertJmxValue(OBJECT_NAME, "ok", "true", true);
+ assertEquals(true, getJmxValue(OBJECT_NAME, "ok"));
Thread.sleep(1500);
resultOk = false;
- assertJmxValue(OBJECT_NAME, "ok", "true", false);
+ assertEquals(false, getJmxValue(OBJECT_NAME, "ok"));
Thread.sleep(1500);
- assertJmxValue(OBJECT_NAME, "log", "contains message=Result is not
ok!", true);
+ assertThat(String.valueOf(getJmxValue(OBJECT_NAME, "log")),
containsString("message=Result is not ok!"));
+
} finally {
jmxServer.unregisterMBean(name);
}
Modified: felix/trunk/healthcheck/docs/felix-health-checks.md
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/docs/felix-health-checks.md?rev=1850448&r1=1850447&r2=1850448&view=diff
==============================================================================
--- felix/trunk/healthcheck/docs/felix-health-checks.md (original)
+++ felix/trunk/healthcheck/docs/felix-health-checks.md Sat Jan 5 00:20:45 2019
@@ -123,6 +123,8 @@ Memory | org.apache.felix.hc.generalchec
CPU | org.apache.felix.hc.generalchecks.CpuCheck | no | Checks for CPU usage -
`cpuPercentageThresholdWarn` (default 95%) can be set to control what CPU usage
produces status `WARN` (check never results in `CRITICAL`)
Thread Usage | org.apache.felix.hc.generalchecks.ThreadUsageCheck | no |
Checks via `ThreadMXBean.findDeadlockedThreads()` for deadlocks and analyses
the CPU usage of each thread via a configurable time period (`samplePeriodInMs`
defaults to 200ms). Uses `cpuPercentageThresholdWarn` (default 95%) to `WARN`
about high thread utilisation.
Bundles Started | org.apache.felix.hc.generalchecks.BundlesStartedCheck | yes
| Checks for started bundles - `includesRegex` and `excludesRegex` control what
bundles are checked.
+JMX Attribute Check | org.apache.felix.hc.generalchecks.JmxAttributeCheckk |
yes | Allows to check an arbitrary JMX attribute (using the configured mbean
`mbean.name`'s attribute `attribute.name`) against a given constraint
`attribute.value.constraint`
+
## Executing Health Checks
Copied:
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/JmxAttributeCheck.java
(from r1850438,
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheck.java)
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/JmxAttributeCheck.java?p2=felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/JmxAttributeCheck.java&p1=felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheck.java&r1=1850438&r2=1850448&rev=1850448&view=diff
==============================================================================
---
felix/trunk/healthcheck/core/src/main/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheck.java
(original)
+++
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/JmxAttributeCheck.java
Sat Jan 5 00:20:45 2019
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
-package org.apache.felix.hc.core.impl;
+package org.apache.felix.hc.generalchecks;
import java.lang.management.ManagementFactory;
@@ -24,34 +24,67 @@ import javax.management.ObjectName;
import org.apache.felix.hc.api.HealthCheck;
import org.apache.felix.hc.api.Result;
+import org.apache.felix.hc.api.ResultLog;
+import org.apache.felix.hc.generalchecks.util.SimpleConstraintChecker;
import org.apache.felix.hc.util.FormattingResultLog;
-import org.apache.felix.hc.util.SimpleConstraintChecker;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** {@link HealthCheck} that checks a single JMX attribute */
@Component(service = HealthCheck.class, configurationPolicy =
ConfigurationPolicy.REQUIRE)
-@Designate(ocd = JmxAttributeHealthCheckConfiguration.class, factory = true)
-public class JmxAttributeHealthCheck implements HealthCheck {
+@Designate(ocd = JmxAttributeCheck.Config.class, factory = true)
+public class JmxAttributeCheck implements HealthCheck {
- private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final Logger LOG =
LoggerFactory.getLogger(JmxAttributeCheck.class);
+ public static final String HC_NAME = "JMX Attribute";
+ public static final String HC_LABEL = "Health Check: " + HC_NAME;
+
+
private String mbeanName;
private String attributeName;
private String constraint;
+ private Result.Status statusForFailedContraint;
- @Activate
- protected void activate(final JmxAttributeHealthCheckConfiguration
configuration) {
- mbeanName = configuration.mbean_name();
- attributeName = configuration.attribute_name();
- constraint = configuration.attribute_value_constraint();
+ @ObjectClassDefinition(name = HC_LABEL, description = "Checks the value of
a single JMX attribute.")
+ @interface Config {
+
+ @AttributeDefinition(name = "Name", description = "Name of this health
check.")
+ String hc_name() default HC_NAME;
- log.debug("Activated with HealthCheck name={}, objectName={},
attribute={}, constraint={}",
- new Object[] { configuration.hc_name(), mbeanName,
attributeName, constraint });
+ @AttributeDefinition(name = "Tags", description = "List of tags for
this health check, used to select subsets of health checks for execution e.g.
by a composite health check.")
+ String[] hc_tags() default {};
+
+ @AttributeDefinition(name = "MBean Name", description = "The name of
the MBean to retrieve the attribute to be checked from.")
+ String mbean_name() default "";
+
+ @AttributeDefinition(name = "Attribute Name", description = "The name
of the MBean attribute to check against the constraing.")
+ String attribute_name() default "";
+
+ @AttributeDefinition(name = "Attribute Constraint", description =
"Constraint on the MBean attribute value. If simple value, uses equals. For
strings constraints like 'CONTAINS mystr', 'STARTS_WITH mystr' or 'ENDS_WITH
mystr' can be used, for numbers constraints like '> 4', '= 7', '< 9' or
'between 3 and 7' work.")
+ String attribute_value_constraint() default "";
+
+ @AttributeDefinition(name = "Status for failed constraint",
description = "Status to fail with if the constraint check fails")
+ Result.Status statusForFailedContraint() default Result.Status.WARN;
+
+ @AttributeDefinition
+ String webconsole_configurationFactory_nameHint() default "JMX MBean
{mbean.name} Attribute '{attribute.name}' constraint:
{attribute.value.constraint}";
+ }
+
+
+ @Activate
+ protected void activate(final Config config) {
+ mbeanName = config.mbean_name();
+ attributeName = config.attribute_name();
+ constraint = config.attribute_value_constraint();
+ statusForFailedContraint = config.statusForFailedContraint();
+ LOG.info("Activated JMX Attribute HC for mbeanName {} attributeName={}
constraint={} statusForFailedContraint={}", mbeanName, attributeName,
constraint, statusForFailedContraint);
}
@Override
@@ -66,10 +99,16 @@ public class JmxAttributeHealthCheck imp
} else {
final Object value = jmxServer.getAttribute(objectName,
attributeName);
resultLog.debug("{} {} returns {}", mbeanName, attributeName,
value);
- new SimpleConstraintChecker().check(value, constraint,
resultLog);
+ boolean matches = new SimpleConstraintChecker().check(value,
constraint);
+ String baseMsg = "JMX attribute "+mbeanName+" ->
'"+attributeName+"': Value [" + value + "] ";
+ if (matches) {
+ resultLog.add(new ResultLog.Entry(Result.Status.OK,
baseMsg+"matches constraint [" + constraint + "]"));
+ } else {
+ resultLog.add(new ResultLog.Entry(
statusForFailedContraint, baseMsg+"does not match constraint [" + constraint +
"]"));
+ }
}
- } catch (final Exception e) {
- log.warn("JMX attribute {}/{} check failed: {}", new Object[] {
mbeanName, attributeName, e });
+ } catch (Exception e) {
+ LOG.warn("JMX attribute {}.{} check failed: {}", mbeanName,
attributeName, e.getMessage(), e);
resultLog.healthCheckError("JMX attribute check failed: {}", e);
}
return new Result(resultLog);
Copied:
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintChecker.java
(from r1850438,
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/util/SimpleConstraintChecker.java)
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintChecker.java?p2=felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintChecker.java&p1=felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/util/SimpleConstraintChecker.java&r1=1850438&r2=1850448&rev=1850448&view=diff
==============================================================================
---
felix/trunk/healthcheck/api/src/main/java/org/apache/felix/hc/util/SimpleConstraintChecker.java
(original)
+++
felix/trunk/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintChecker.java
Sat Jan 5 00:20:45 2019
@@ -15,20 +15,26 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
-package org.apache.felix.hc.util;
+package org.apache.felix.hc.generalchecks.util;
-import org.apache.felix.hc.api.Result;
-import org.apache.felix.hc.api.ResultLog;
+import org.apache.commons.lang3.StringUtils;
/** Simple check of numeric values against expressions like < N, > N,
between two values etc. See the SimpleConstraintCheckerTest for
* examples. */
public class SimpleConstraintChecker {
public static final String CONTAINS = "contains";
+ public static final String STARTS_WITH = "starts_with";
+ public static final String ENDS_WITH = "ends_with";
- /** Check value against expression and report to result */
- public void check(Object inputValue, String constraint, ResultLog
resultLog) {
+ /** Check value against expression and report to result
+ * @param statusForFailedContraint */
+ public boolean check(Object inputValue, String constraint) throws
NumberFormatException {
+ if(inputValue == null) {
+ return false;
+ }
+
final String stringValue = inputValue == null ? "" :
inputValue.toString();
if (constraint == null || constraint.trim().length() == 0) {
@@ -37,41 +43,35 @@ public class SimpleConstraintChecker {
final String[] parts = constraint.split(" ");
boolean matches = false;
- try {
- if (constraint.startsWith(">") && parts.length == 2) {
- final int value = Integer.valueOf(stringValue).intValue();
- matches = value > Integer.valueOf(parts[1]);
-
- } else if (constraint.startsWith("<") && parts.length == 2) {
- final int value = Integer.valueOf(stringValue).intValue();
- matches = value < Integer.valueOf(parts[1]);
-
- } else if (parts.length == 4 &&
"between".equalsIgnoreCase(parts[0]) && "and".equalsIgnoreCase(parts[2])) {
- final int value = Integer.valueOf(stringValue).intValue();
- final int lowerBound = Integer.valueOf(parts[1]);
- final int upperBound = Integer.valueOf(parts[3]);
- matches = value > lowerBound && value < upperBound;
-
- } else if (parts.length > 1 &&
CONTAINS.equalsIgnoreCase(parts[0])) {
- final String pattern =
constraint.substring(CONTAINS.length()).trim();
- matches = stringValue.contains(pattern);
-
- } else {
- matches = constraint.equals(stringValue);
- }
- } catch (NumberFormatException nfe) {
- resultLog.add(new ResultLog.Entry(
- Result.Status.WARN,
- "Invalid numeric value [" + inputValue + "] while
evaluating " + constraint));
- }
- if (matches) {
- resultLog.add(new ResultLog.Entry(
- "Value [" + inputValue + "] matches constraint [" +
constraint + "]", true));
+ if (constraint.startsWith(">") && parts.length == 2) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ matches = value > Integer.valueOf(parts[1]);
+
+ } else if (constraint.startsWith("<") && parts.length == 2) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ matches = value < Integer.valueOf(parts[1]);
+
+ } else if (parts.length == 4 && "between".equalsIgnoreCase(parts[0])
&& "and".equalsIgnoreCase(parts[2])) {
+ final int value = Integer.valueOf(stringValue).intValue();
+ final int lowerBound = Integer.valueOf(parts[1]);
+ final int upperBound = Integer.valueOf(parts[3]);
+ matches = value > lowerBound && value < upperBound;
+
+ } else if (parts.length > 1 && CONTAINS.equalsIgnoreCase(parts[0])) {
+ final String pattern = StringUtils.join(parts, " ", 1,
parts.length);
+ matches = stringValue.contains(pattern);
+ } else if (parts.length > 1 && STARTS_WITH.equalsIgnoreCase(parts[0]))
{
+ final String pattern = StringUtils.join(parts, " ", 1,
parts.length);
+ matches = stringValue.startsWith(pattern);
+ } else if (parts.length > 1 && ENDS_WITH.equalsIgnoreCase(parts[0])) {
+ final String pattern = StringUtils.join(parts, " ", 1,
parts.length);
+ matches = stringValue.endsWith(pattern);
} else {
- resultLog.add(new ResultLog.Entry(
- Result.Status.WARN,
- "Value [" + inputValue + "] does not match constraint [" +
constraint + "]"));
+ matches = constraint.equals(stringValue);
}
+
+ return matches;
+
}
}
\ No newline at end of file
Copied:
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/JmxAttributeHealthCheckTest.java
(from r1850438,
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckTest.java)
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/JmxAttributeHealthCheckTest.java?p2=felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/JmxAttributeHealthCheckTest.java&p1=felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckTest.java&r1=1850438&r2=1850448&rev=1850448&view=diff
==============================================================================
---
felix/trunk/healthcheck/core/src/test/java/org/apache/felix/hc/core/impl/JmxAttributeHealthCheckTest.java
(original)
+++
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/JmxAttributeHealthCheckTest.java
Sat Jan 5 00:20:45 2019
@@ -15,21 +15,22 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
-package org.apache.felix.hc.core.impl;
+package org.apache.felix.hc.generalchecks;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.apache.felix.hc.api.Result;
+import org.apache.felix.hc.generalchecks.JmxAttributeCheck;
import org.junit.Test;
public class JmxAttributeHealthCheckTest {
static void assertJmxValue(String objectName, String attributeName, String
constraint, boolean expected) {
- final JmxAttributeHealthCheck hc = new JmxAttributeHealthCheck();
+ final JmxAttributeCheck hc = new JmxAttributeCheck();
- final JmxAttributeHealthCheckConfiguration configuration =
mock(JmxAttributeHealthCheckConfiguration.class);
+ final JmxAttributeCheck.Config configuration =
mock(JmxAttributeCheck.Config.class);
when(configuration.mbean_name()).thenReturn(objectName);
when(configuration.attribute_name()).thenReturn(attributeName);
when(configuration.attribute_value_constraint()).thenReturn(constraint);
Copied:
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintCheckerTest.java
(from r1850438,
felix/trunk/healthcheck/api/src/test/java/org/apache/felix/hc/util/SimpleConstraintCheckerTest.java)
URL:
http://svn.apache.org/viewvc/felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintCheckerTest.java?p2=felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintCheckerTest.java&p1=felix/trunk/healthcheck/api/src/test/java/org/apache/felix/hc/util/SimpleConstraintCheckerTest.java&r1=1850438&r2=1850448&rev=1850448&view=diff
==============================================================================
---
felix/trunk/healthcheck/api/src/test/java/org/apache/felix/hc/util/SimpleConstraintCheckerTest.java
(original)
+++
felix/trunk/healthcheck/generalchecks/src/test/java/org/apache/felix/hc/generalchecks/util/SimpleConstraintCheckerTest.java
Sat Jan 5 00:20:45 2019
@@ -15,152 +15,148 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
-package org.apache.felix.hc.util;
+package org.apache.felix.hc.generalchecks.util;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import org.apache.felix.hc.api.Result;
-import org.apache.felix.hc.api.ResultLog;
import org.junit.Before;
import org.junit.Test;
public class SimpleConstraintCheckerTest {
- private ResultLog resultLog;
private final SimpleConstraintChecker checker = new
SimpleConstraintChecker();
@Before
public void setup() {
- resultLog = new ResultLog();
}
@Test
public void testStringEquals() {
final String s = "test_" + System.currentTimeMillis();
- checker.check(s, s, resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(s, s));
}
@Test
public void testStringNotEquals() {
final String s = "test_" + System.currentTimeMillis();
- checker.check(s, "something else", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check(s, "something else"));
}
@Test
public void testFiveEquals() {
final String s = "5";
- checker.check(s, s, resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(s, s));
}
@Test
public void testIntTwelveEquals() {
- checker.check(12, "12", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(12, "12"));
}
@Test
public void testIntTwelveGreaterThan() {
- checker.check(12, "> 11", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(12, "> 11"));
}
@Test
public void testFiveNotEquals() {
- checker.check("5", "foo", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("5", "foo"));
}
@Test
public void testNullNotEquals() {
- checker.check(null, "foo", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check(null, "foo"));
}
@Test
public void testNullNotGreater() {
- checker.check(null, "> 2", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check(null, "> 2"));
}
@Test
public void testGreaterThanTrue() {
- checker.check("5", "> 2", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check("5", "> 2"));
}
@Test
public void testGreaterThanFalse() {
- checker.check("5", "> 12", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("5", "> 12"));
}
@Test
public void testLessThanTrue() {
- checker.check("5", "< 12", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check("5", "< 12"));
}
@Test
public void testLessThanFalse() {
- checker.check("5", "< 2", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("5", "< 2"));
}
@Test
public void testBetweenA() {
- checker.check("5", "between 2 and 6", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check("5", "between 2 and 6"));
}
@Test
public void testBetweenB() {
- checker.check("5", "between 12 and 16", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("5", "between 12 and 16"));
}
@Test
public void testBetweenC() {
- checker.check(5L, "between 12 and 16", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check(5L, "between 12 and 16"));
}
@Test
public void testBetweenD() {
- checker.check(5L, "between 4 and 16", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(5L, "between 4 and 16"));
}
@Test
public void testBetweenE() {
- checker.check(5L, "betWEEN 4 aND 16", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check(5L, "betWEEN 4 aND 16"));
}
- @Test
+ @Test(expected=NumberFormatException.class)
public void testNotAnInteger() {
- checker.check("foo", "between 12 and 16", resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("foo", "between 12 and 16"));
}
@Test
public void testContainsA() {
- checker.check("This is a NICE STRING ok?", "contains NICE STRING",
resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check("This is a NICE STRING ok?", "contains NICE
STRING"));
}
@Test
public void testContainsB() {
- checker.check("This is a NICE TOUCH ok?", "contains NICE STRING",
resultLog);
- assertFalse(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertFalse(checker.check("This is a NICE TOUCH ok?", "contains NICE
STRING"));
}
@Test
public void testContainsC() {
- checker.check("This is a NICE TOUCH ok?", "contains NICE", resultLog);
- assertTrue(resultLog.getAggregateStatus().equals(Result.Status.OK));
+ assertTrue(checker.check("This is a NICE TOUCH ok?", "contains NICE"));
+ }
+
+ @Test
+ public void testStartsWithA() {
+ assertTrue(checker.check("This is a NICE TOUCH ok?", "STARTS_WITH This
is"));
+ }
+
+ @Test
+ public void testStartsWithB() {
+ assertFalse(checker.check("This is a NICE TOUCH ok?", "STARTS_WITH
is"));
+ }
+
+ @Test
+ public void testEndsWithA() {
+ assertTrue(checker.check("This is a NICE TOUCH ok?", "ENDS_WITH TOUCH
ok?"));
}
+
+ @Test
+ public void testEndsWithB() {
+ assertFalse(checker.check("This is a NICE TOUCH ok?", "ENDS_WITH is"));
+ }
+
}