public boolean isOffline(String method) { if (offline) { LOGGER.warn(getBoilerPlate("Working offline cannot run test: " + method, '=', 80)); } return offline; }
private String resolveString(CoreEvent event, ValueResolver resolver) throws MuleException { try (ValueResolvingContext context = getResolvingContextFor(event)) { Object value = resolver.resolve(context); return value != null ? StringMessageUtils.toString(value) : null; } }
String msg = getBoilerPlate("Message Received in flow: " + getLocation().getRootContainerName() + ". Content is: " + truncate(message.getPayload().getValue().toString(), 100, true), '*', 80);
@Test public void testTruncate() { String msg = "this is a test message for truncating"; String result = StringMessageUtils.truncate(msg, 100, true); assertEquals(msg, result); result = StringMessageUtils.truncate(msg, 10, false); assertEquals("this is a ...", result); result = StringMessageUtils.truncate(msg, 10, true); assertEquals("this is a ...[10 of 37]", result); }
@Test public void testFormattedString() throws Exception { String result; String msg1 = "There is not substitution here"; result = StringMessageUtils.getFormattedMessage(msg1, null); assertEquals(msg1, result); result = StringMessageUtils.getFormattedMessage(msg1, new Object[] {}); assertEquals(msg1, result); String msg2 = "There should be a variable {0}, {1} and {2}"; result = StringMessageUtils.getFormattedMessage(msg2, new Object[] {"here", "there", "everywhere"}); assertEquals("There should be a variable here, there and everywhere", result); }
public void setKey(String rawKey) { this.key = StringMessageUtils.getBytes(rawKey); }
try { logger.trace("Response payload: \n" + truncate(((ExtendedTransformationService) transformationService).getPayloadForLogging(resultMessage), 100, false)); } catch (Exception e) {
@Test public void testFormattedString() throws Exception { String result; String msg1 = "There is not substitution here"; result = StringMessageUtils.getFormattedMessage(msg1, null); assertEquals(msg1, result); result = StringMessageUtils.getFormattedMessage(msg1, new Object[] {}); assertEquals(msg1, result); String msg2 = "There should be a variable {0}, {1} and {2}"; result = StringMessageUtils.getFormattedMessage(msg2, new Object[] {"here", "there", "everywhere"}); assertEquals("There should be a variable here, there and everywhere", result); }
private void printTestHeader() { if (verbose) { System.out.println(getBoilerPlate(getTestHeader(), '=', 80)); } }
@Test public void toStringOnClassShouldReturnClassName() { Object test = getClass(); String result = StringMessageUtils.toString(test); assertEquals(getClass().getName(), result); }
@Test public void testTruncate() { String msg = "this is a test message for truncating"; String result = StringMessageUtils.truncate(msg, 100, true); assertEquals(msg, result); result = StringMessageUtils.truncate(msg, 10, false); assertEquals("this is a ...", result); result = StringMessageUtils.truncate(msg, 10, true); assertEquals("this is a ...[10 of 37]", result); }
private void doCallback(byte[] startData, long startDataSize, byte[] endData, long endDataSize, long endRingPointer, long streamLength, CoreEvent event) throws Exception { // make a nice summary of the data StringBuilder result = new StringBuilder("Received stream"); result.append("; length: "); result.append(streamLength); result.append("; '"); for (long i = 0; i < startDataSize; ++i) { result.append((char) startData[(int) i]); } long endSize = Math.min(endDataSize, STREAM_SAMPLE_SIZE); if (endSize > 0) { result.append("..."); for (long i = 0; i < endSize; ++i) { result.append((char) endData[(int) ((endRingPointer + i) % STREAM_SAMPLE_SIZE)]); } } result.append("'"); summary = result.toString(); String msg = getBoilerPlate("Message Received in service: " + this.getLocation().getRootContainerName() + ". " + summary + "\n callback: " + eventCallback, '*', 80); logger.info(msg); if (eventCallback != null) { eventCallback.eventReceived(event, this, muleContext); } }
@Test public void toStringOnListLargerThanMaximumOutputLengthShouldReturnAbbreviatedStringRepresentation() { // create a Collection that is too long to be printed List<Integer> list = new ArrayList<Integer>(100); for (int i = 0; i < 100; i++) { list.add(new Integer(i)); } // the String will contain not more than exactly MAX_ARRAY_LENGTH elements String result = StringMessageUtils.toString(list); assertTrue(result.endsWith("[..]]")); assertEquals(StringMessageUtils.MAX_ELEMENTS - 1, countMatches(result, ",")); }
try { logger.trace("Response payload: \n" + truncate(((ExtendedTransformationService) muleContext.getTransformationService()) .getPayloadForLogging(resultMessage), 100, false)); } catch (Exception e) {
/** * It delegates to the original {@link ClassLoaderFilter} if it is not exported it will check againts the list of exported * classes. * * @param name class name to check. Non empty. * @return true if the resource is exported, false otherwise */ @Override public boolean exportsClass(final String name) { checkArgument(!isEmpty(name), "Class name cannot be empty"); boolean exported = classLoaderFilter.exportsClass(name); if (!exported) { exported = exportedClasses.get(name) != null; if (exported) { logger.warn(StringMessageUtils .getBoilerPlate(newArrayList("WARNING:", " ", "Class: '" + name + "' is NOT exposed by the plugin but it will be visible " + "due to it was manually forced to be exported for testing purposes.", " ", "Check if this is really necessary, this class won't be visible in standalone mode."), '*', DEFAULT_MESSAGE_WIDTH)); } } return exported; }
@Test public void toStringOnStringShouldReturnTheString() { String input = "Oscar"; String result = StringMessageUtils.toString(input); assertEquals(input, result); }
messages.addAll(filePathByArtifactId.entrySet().stream().map(entry -> entry.getKey() + " -> (" + (entry.getValue()) + ")") .collect(toList())); logger.debug(getBoilerPlate(newArrayList(messages), '*', 150));
@Test public void toStringOnByteArrayShouldReturnStringRepresentation() { Object test = new byte[] {1, 2}; String result = StringMessageUtils.toString(test); assertEquals("{1,2}", result); }
/** * Will shut down the server displaying the cause and time of the shutdown * * @param e the exception that caused the shutdown */ public void shutdown(Throwable e) throws MuleException { I18nMessage msg = fatalErrorWhileRunning(); MuleException muleException = getRootMuleException(e); if (muleException != null) { logger.error(muleException.getDetailedMessage()); } else { logger.error(msg.toString() + " " + e.getMessage(), e); } List<String> msgs = new ArrayList<>(); msgs.add(msg.getMessage()); Throwable root = getRootException(e); msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")"); msgs.add(" "); msgs.add(fatalErrorInShutdown().getMessage()); String shutdownMessage = getBoilerPlate(msgs, '*', 80); logger.error(shutdownMessage); doShutdown(); System.exit(1); }