public static <T> void assertThat(T object, Predicate<T> condition) { assertThat(object, condition, null); } public static <T> void assertThat(T object, Predicate<T> condition, String message) {
public static void assertInstanceOf(Object obj, Class<?> type) { assertThat(obj, Predicates.instanceOf(type), "Expected "+type+" but found "+(obj==null ? "null" : obj+" ("+obj.getClass()+")")); }
public static void assertStringDoesNotContain(String input, String phrase1ToNotContain, String ...optionalOtherPhrasesToNotContain) { if (input==null) fail("Input is null."); if (phrase1ToNotContain!=null) { assertThat(input, Predicates.not(StringPredicates.containsLiteral(phrase1ToNotContain))); } for (String otherPhrase: optionalOtherPhrasesToNotContain) { if (otherPhrase!=null) { assertThat(input, Predicates.not(StringPredicates.containsLiteral(otherPhrase))); } } }
public static void assertStringMatchesRegex(String input, String regex1ToMatch, String ...optionalOtherRegexesToMatch) { if (input==null) fail("Input is null."); if (regex1ToMatch!=null) { assertThat(input, StringPredicates.matchesRegex(regex1ToMatch)); } for (String otherRegex: optionalOtherRegexesToMatch) { if (otherRegex!=null) { assertThat(input, StringPredicates.matchesRegex(otherRegex)); } } }
public static void assertStringContains(String input, String phrase1ToContain, String ...optionalOtherPhrasesToContain) { if (input==null) fail("Input is null."); if (phrase1ToContain!=null) { assertThat(input, StringPredicates.containsLiteral(phrase1ToContain)); } for (String otherPhrase: optionalOtherPhrasesToContain) { if (otherPhrase!=null) { assertThat(input, StringPredicates.containsLiteral(otherPhrase)); } } }
public static void assertStringContainsIgnoreCase(String input, String phrase1ToContain, String ...optionalOtherPhrasesToContain) { if (input==null) fail("Input is null."); if (phrase1ToContain!=null) { assertThat(input, StringPredicates.containsLiteralIgnoreCase(phrase1ToContain)); } for (String otherPhrase: optionalOtherPhrasesToContain) { if (otherPhrase!=null) { assertThat(input, StringPredicates.containsLiteralIgnoreCase(otherPhrase)); } } }
@Test public void testManagedLocationsSimpleCreateAndCleanup() { Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); Location loc = mgmt.getLocationRegistry().getLocationManaged("localhost"); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); mgmt.getLocationManager().unmanage(loc); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); }
@Test public void testManagedLocationsNamedCreateAndCleanup() { Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); mgmt.getLocationRegistry().updateDefinedLocationNonPersisted( new BasicLocationDefinition("lh1", "localhost", null) ); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); // currently such defined locations do NOT appear in catalog -- see CatalogYamlLocationTest Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Location loc = mgmt.getLocationRegistry().getLocationManaged("lh1"); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); mgmt.getLocationManager().unmanage(loc); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); }
private void assertLocationRegistryCount(int size) { Asserts.assertThat(mgmt().getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(size)); } private void assertLocationManagerInstancesCount(int size) {
private void assertCatalogCount(int size) { Asserts.assertThat(mgmt().getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(size)); }
private void assertLocationManagerInstancesCount(int size) { Asserts.assertThat(mgmt().getLocationManager().getLocations(), CollectionFunctionals.sizeEquals(size)); } private void assertCatalogCount(int size) {
waitForApplicationTasks(app); Asserts.assertThat(app.getChildren(), CollectionFunctionals.empty()); Asserts.assertThat((Iterable<?>)result, CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(app.getChildren(), CollectionFunctionals.sizeEquals(1)); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getId(), Iterables.getOnlyElement((Iterable<?>)result));
public void testTransformingSuppressDuplicates() { RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>(); app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record); entity.enrichers().add(Enrichers.builder() .transforming(STR1) .publishing(STR2) .computing(Functions.<String>identity()) .suppressDuplicates(true) .build()); entity.sensors().set(STR1, "myval"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1)); EntityAsserts.assertAttributeEquals(entity, STR2, "myval"); entity.sensors().set(STR1, "myval2"); entity.sensors().set(STR1, "myval2"); entity.sensors().set(STR1, "myval3"); EntityAsserts.assertAttributeEqualsContinually(entity, STR2, "myval3"); Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(3)); }