/** * Asserts that a condition is true. If it isn't, * an AssertionError, with the given message, is thrown. * @param condition the condition to evaluate * @param message the assertion error message */ public static void assertTrue(boolean condition, String message) { if (!condition) fail(message); }
/** * Asserts that a condition is false. If it isn't, * an AssertionError, with the given message, is thrown. * @param condition the condition to evaluate * @param message the assertion error message */ public static void assertFalse(boolean condition, String message) { if (condition) fail(message); } public static void assertFalse(boolean condition) {
public static void assertFalse(boolean condition) { if (condition) fail(); }
/** * Asserts that a condition is true. If it isn't, an AssertionError is thrown. * @param condition the condition to evaluate */ public static void assertTrue(boolean condition) { if (!condition) fail(); }
public void assertHasRequest(Predicate<? super HttpRequest> filter) { for (HttpRequest req : requests) { if (filter.apply(req)) { return; } } Asserts.fail("No request matching filter "+ filter); }
@Override public boolean apply(Throwable e) { for (Class<?> validException: validExceptions) { if (validException.isInstance(e)) return true; } fail("Test threw exception of unexpected type "+e.getClass()+"; expecting "+validExceptions); return false; } });
/** Asserts that the given HTTP status code indicates "success", i.e. {@link #isHealthyStatusCode(int)} is true */ public static void assertHealthyStatusCode(int code) { if (isHealthyStatusCode(code)) return; Asserts.fail("Expected success status code, got: " + code); }
/** Asserts that the given HTTP status code does not indicate "success", i.e. {@link #isHealthyStatusCode(int)} returns false */ public static void assertNotHealthyStatusCode(int code) { if (!isHealthyStatusCode(code)) return; Asserts.fail("Expected non-success status code, got: " + code); }
/** Asserts that the given HTTP status code indicates "client error", i.e. {@link #isClientErrorStatusCode(int)} is true */ public static void assertClientErrorStatusCode(int code) { if (isClientErrorStatusCode(code)) return; Asserts.fail("Expected client error status code, got: " + code); }
/** Asserts that the given HTTP status code indicates "server error", i.e. {@link #isServerErrorStatusCode(int)} is true */ public static void assertServerErrorStatusCode(int code) { if (isServerErrorStatusCode(code)) return; Asserts.fail("Expected server error status code, got: " + code); }
public static <T> void assertNotPresent(Maybe<T> candidate) { if (candidate.isAbsent()) return; fail("Expected absent value; instead got: "+candidate.get()); }
public static void assertErrorContentContainsText(final String url, final String phrase, final String ...additionalPhrases) { try { String contents = HttpTool.getErrorContent(url); Asserts.assertTrue(contents != null && contents.length() > 0); for (String text: Lists.asList(phrase, additionalPhrases)) { if (!contents.contains(text)) { LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents); Asserts.fail("URL "+url+" does not contain text: "+text); } } } catch (Exception e) { throw propagateAsAssertionError(e); } }
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))); } } }
private int findPort() { for (int port = 58767; port < 60000; port++) { if (Networking.isPortAvailable(port)) { return port; } } throw Asserts.fail("This test requires that at least one port a little bit under port 60000 not be in use."); }
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)); } } }
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)); } } }
@Override public void run() { String targetStatus = monitNode.getAttribute(MonitNode.MONIT_TARGET_PROCESS_STATUS); LOG.debug("MonitNode target status: {}", targetStatus); assertEquals(targetStatus, "Running"); try { initialPid[0] = Files.readFirstLine(new File(mySqlNode.getAttribute(SoftwareProcess.PID_FILE)), Charset.defaultCharset()); LOG.debug("Initial PID: {}", initialPid[0]); } catch (IOException e) { Asserts.fail("Could not read PID file: " + e); } } });
@Override public void run() { final Set<Task<?>> tasksWithAllTags = mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(BrooklynTaskTags.EFFECTOR_TAG, BrooklynTaskTags.tagForContextEntity(entity))); Task<?> entityTask = null; for (Task<?> item : tasksWithAllTags) { final String itemName = getEffectorName(item); entityTask = itemName.equals(effectorName) ? item : entityTask; } if (entityTask == null) { Asserts.fail("Could not find task for effector " + effectorName); } String blockingDetails = getBlockingDetails(entityTask); assertTrue(blockingDetails.contains(blockingDetailsSnippet)); }}); }