@Override public Predicate<CharSequence> apply(String input) { return containsLiteral(input); } }));
@Test public static void testContainsLiteral() { Assert.assertTrue(StringPredicates.containsLiteral("xx").apply("texxxt tessst")); Assert.assertFalse(StringPredicates.containsLiteral("xx").apply("text test")); Assert.assertFalse(StringPredicates.containsLiteral("xx").apply("texXxt tessst")); Assert.assertTrue(StringPredicates.containsLiteralIgnoreCase("xx").apply("texxxt tessst")); Assert.assertFalse(StringPredicates.containsLiteralIgnoreCase("xx").apply("text test")); Assert.assertTrue(StringPredicates.containsLiteralIgnoreCase("xx").apply("texXxt tessst")); Assert.assertTrue(StringPredicates.containsAllLiterals("xx", "ss").apply("texxxt tessst")); Assert.assertFalse(StringPredicates.containsAllLiterals("xx", "tt").apply("texxxt tessst")); }
public static <T extends CharSequence> Predicate<T> containsAllLiterals(final String... fragments) { List<Predicate<CharSequence>> fragmentPredicates = Lists.newArrayList(); for (String fragment : fragments) { fragmentPredicates.add(containsLiteral(fragment)); } return Predicates.and(fragmentPredicates); }
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 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)); } } }
@Test public void testValueSatisfies() throws Exception { Predicate<SensorEvent<String>> predicate = SensorEventPredicates.valueSatisfies(StringPredicates.containsLiteral("my")); assertTrue(predicate.apply(new BasicSensorEvent<String>(sensor1, app, "myval"))); assertFalse(predicate.apply(new BasicSensorEvent<String>(sensor1, app, "wrongVal"))); } }
assertSubTaskFailures(entity, ImmutableMap.of(taskRegexFailed, StringPredicates.containsLiteral("for "+cmdFailed)));
Assert.assertEquals(ping.get().trim(), "hello"); EntityAsserts.assertAttributeEventually(netcat, SENSOR_OUTPUT_ALL, StringPredicates.containsLiteral("hi netcat")); log.info("invoked ping from "+pinger+" to "+netcat+", 'all' sensor shows:\n"+ netcat.getAttribute(SENSOR_OUTPUT_ALL)); Assert.assertEquals(ping.get().trim(), "hello"); EntityAsserts.assertAttributeEventually(netcat, SENSOR_OUTPUT_ALL, StringPredicates.containsLiteral("yo yo yo")); log.info("invoked ping again from "+pinger+" to "+netcat+", 'all' sensor shows:\n"+ netcat.getAttribute(SENSOR_OUTPUT_ALL)); EntityAsserts.assertAttributeEventually(app, Sensors.newStringSensor("output.last"), StringPredicates.containsLiteral("yo yo yo"));
@Test(groups="Integration") public void testReturnsSshStderr() throws Exception { final String cmd = "thiscommanddoesnotexist"; feed = SshFeed.builder() .entity(entity) .machine(machine) .poll(new CommandPollConfig<String>(SENSOR_STRING) .command(cmd) .onFailure(SshValueFunctions.stderr())) .build(); EntityAsserts.assertAttributeEventually(entity, SENSOR_STRING, StringPredicates.containsLiteral(cmd)); }
@Test(groups="Live") public void testReturnsStderr() throws Exception { final String cmd = "thiscommanddoesnotexist"; feed = CmdFeed.builder() .entity(entity) .machine(machine) .poll(new CommandPollConfig<String>(SENSOR_STRING) .command(cmd) .onFailure(SshValueFunctions.stderr())) .build(); EntityAsserts.assertAttributeEventually(entity, SENSOR_STRING, StringPredicates.containsLiteral(cmd)); }
@Test(groups="Integration") public void testAddedEarly() throws Exception { final TestEntity entity2 = app.addChild(EntitySpec.create(TestEntity.class) .location(machine) .addInitializer(new EntityInitializer() { @Override public void apply(EntityLocal entity) { SshFeed.builder() .entity(entity) .onlyIfServiceUp() .poll(new CommandPollConfig<String>(SENSOR_STRING) .command("echo hello") .onSuccess(SshValueFunctions.stdout())) .build(); } })); // TODO would be nice to hook in and assert no errors EntityAsserts.assertAttributeEqualsContinually(entity2, SENSOR_STRING, null); entity2.sensors().set(Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEventually(entity2, SENSOR_STRING, StringPredicates.containsLiteral("hello")); }
@Test(groups="Live") public void testAddedEarly() throws Exception { final TestEntity entity2 = app.addChild(EntitySpec.create(TestEntity.class) .location(machine) .addInitializer(new EntityInitializer() { @Override public void apply(EntityLocal entity) { CmdFeed.builder() .entity(entity) .onlyIfServiceUp() .poll(new CommandPollConfig<String>(SENSOR_STRING) .command("echo hello") .onSuccess(SshValueFunctions.stdout())) .build(); } })); // TODO would be nice to hook in and assert no errors EntityAsserts.assertAttributeEqualsContinually(entity2, SENSOR_STRING, null); entity2.sensors().set(Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEventually(entity2, SENSOR_STRING, StringPredicates.containsLiteral("hello")); }
@Test(groups="Integration") public void testFailsOnNonZero() throws Exception { feed = SshFeed.builder() .entity(entity) .machine(machine) .poll(new CommandPollConfig<String>(SENSOR_STRING) .command("exit 123") .onFailure(new Function<SshPollValue, String>() { @Override public String apply(SshPollValue input) { return "Exit status " + input.getExitStatus(); }})) .build(); EntityAsserts.assertAttributeEventually(entity, SENSOR_STRING, StringPredicates.containsLiteral("Exit status 123")); }
@Test(groups="Live") public void testFailsOnNonZero() throws Exception { feed = CmdFeed.builder() .entity(entity) .machine(machine) .poll(new CommandPollConfig<String>(SENSOR_STRING) .command("exit 123") .onFailure(new Function<SshPollValue, String>() { @Override public String apply(SshPollValue input) { return "Exit status " + input.getExitStatus(); }})) .build(); EntityAsserts.assertAttributeEventually(entity, SENSOR_STRING, StringPredicates.containsLiteral("Exit status 123")); }
@Test public void testCustomizerPropagatesException() throws Exception { SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocationThrowsException.class) .configure("address", "4.3.2.1")); FixedListMachineProvisioningLocation<?> provisioningLoc = mgmt.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure("machines", MutableSet.of(machine))); MachineEntity entity = app.createAndManageChild(EntitySpec.create(MachineEntity.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true) .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS.getName()), ImmutableSet.of(customizer))); try { entity.start(ImmutableList.of(provisioningLoc)); fail(); } catch (RuntimeException e) { if (Exceptions.getFirstThrowableMatching(e, Predicates.compose(StringPredicates.containsLiteral("simulated failure"), Functions.toStringFunction())) == null) { throw e; }; assertFalse(Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).isPresent()); } }