private void assertDefaultEncoding(DataType dataType) throws Exception { assertThat(dataType.getMediaType().getCharset().get(), is(getDefaultEncoding(muleContext))); }
@Test public void testEnvironment() throws Exception { Map env = SystemUtils.getenv(); assertNotNull(env); assertFalse(env.isEmpty()); assertSame(env, SystemUtils.getenv()); String envVarToTest = "PATH"; if (IS_OS_WINDOWS) { // Depending on the presence of Cygwin, it might be one or the other. if (env.get(envVarToTest) == null) { envVarToTest = "Path"; } } assertNotNull(env.get(envVarToTest)); }
/** * Allows subclasses to obtain command line options differently. * <p/> * Useful for testing purposes * * @param args arguments received from command line * @return map containing each configuration option name and value */ Map<String, Object> getCommandLineOptions(String[] args) { Map<String, Object> commandlineOptions; try { commandlineOptions = SystemUtils.getCommandLineOptions(args, CLI_OPTIONS); } catch (MuleException me) { throw new IllegalArgumentException(me.toString()); } return commandlineOptions; }
public static boolean isSupportedJdkVendor() { return SystemUtils.isSunJDK() || SystemUtils.isAppleJDK() || SystemUtils.isIbmJDK(); }
@Test public void testAddVariable() throws MuleException { addVariableProcessor.setIdentifier(PLAIN_STRING_KEY); addVariableProcessor.setValue(PLAIN_STRING_VALUE); addVariableProcessor.initialise(); event = addVariableProcessor.process(event); verifyAdded(event, PLAIN_STRING_KEY, PLAIN_STRING_VALUE); assertThat(getVariableDataType(event, PLAIN_STRING_KEY), like(String.class, ANY, getDefaultEncoding(mockMuleContext))); }
public static String getenv(String name) { return (String) SystemUtils.getenv().get(name); }
protected void init(String[] args) throws IllegalArgumentException { // TODO(pablo.kraan): move initialization of others classes outside this method Map<String, Object> commandlineOptions; try { commandlineOptions = SystemUtils.getCommandLineOptions(args, CLI_OPTIONS); } catch (MuleException me) { throw new IllegalArgumentException(me.toString()); } // set our own UrlStreamHandlerFactory to become more independent of system // properties MuleUrlStreamHandlerFactory.installUrlStreamHandlerFactory(); MuleArtifactUrlStreamHandler.register(); // Startup properties String propertiesFile = (String) commandlineOptions.get("props"); if (propertiesFile != null) { setStartupPropertiesFile(propertiesFile); } StartupContext.get().setStartupOptions(commandlineOptions); }
@Test public void testAddVariableWithExpressionValue() throws MuleException { addVariableProcessor.setIdentifier(PLAIN_STRING_KEY); addVariableProcessor.setValue(EXPRESSION); addVariableProcessor.initialise(); event = addVariableProcessor.process(event); verifyAdded(event, PLAIN_STRING_KEY, EXPRESSION_VALUE); assertThat(getVariableDataType(event, PLAIN_STRING_KEY), like(String.class, ANY, getDefaultEncoding(mockMuleContext))); }
@Test public void testEnvironment() throws Exception { Map env = SystemUtils.getenv(); assertNotNull(env); assertFalse(env.isEmpty()); assertSame(env, SystemUtils.getenv()); String envVarToTest = "PATH"; if (IS_OS_WINDOWS) { // Depending on the presence of Cygwin, it might be one or the other. if (env.get(envVarToTest) == null) { envVarToTest = "Path"; } } assertNotNull(env.get(envVarToTest)); }
@Test public void testAddVariableWithExpressionKey() throws MuleException { addVariableProcessor.setIdentifier(EXPRESSION); addVariableProcessor.setValue(PLAIN_STRING_VALUE); addVariableProcessor.initialise(); event = addVariableProcessor.process(event); verifyAdded(event, EXPRESSION_VALUE, PLAIN_STRING_VALUE); assertThat(getVariableDataType(event, EXPRESSION_VALUE), like(String.class, ANY, getDefaultEncoding(mockMuleContext))); }
/** * {@inheritDoc} */ @Override public void handle(Result<T, A> result, SourceCallbackContext context) { resolveInitializationParams.runOnce(); checkArgument(context instanceof SourceCallbackContextAdapter, "The supplied context was not created through this callback, " + "you naughty developer"); SourceCallbackContextAdapter contextAdapter = (SourceCallbackContextAdapter) context; validateNotifications(contextAdapter); MessageProcessContext messageProcessContext = processContextSupplier.get(); MediaType mediaType = resolveMediaType(result); PayloadMediaTypeResolver payloadMediaTypeResolver = new PayloadMediaTypeResolver(getDefaultEncoding(muleContext), defaultMediaType, encodingParam, mimeTypeInitParam); SourceResultAdapter resultAdapter = new SourceResultAdapter(result, cursorProviderFactory, mediaType, returnsListOfMessages, context.getCorrelationId(), payloadMediaTypeResolver); Message message = of(resultAdapter); executeFlow(context, messageProcessContext, message); contextAdapter.dispatched(); }
@Test public void operationReturnsOperationResultWhichKeepsNoValues() throws Exception { Object payload = new Object(); MediaType mediaType = ANY.withCharset(getDefaultEncoding(context)); Object attributes = mock(Object.class); when(operationExecutor.execute(any(ExecutionContext.class))) .thenReturn(just(builder().output(payload).mediaType(mediaType).attributes(attributes).build())); Message message = messageProcessor.process(event).getMessage(); assertThat(message, is(notNullValue())); assertThat(message.getPayload().getValue(), is(sameInstance(payload))); assertThat(message.getAttributes().getValue(), is(sameInstance(attributes))); assertThat(message.getPayload().getDataType().getMediaType(), is(mediaType)); }
@Test public void operationReturnsOperationResultOnTarget() throws Exception { target = TARGET_VAR; messageProcessor = setUpOperationMessageProcessor(); Object payload = new Object(); MediaType mediaType = ANY.withCharset(getDefaultEncoding(context)); Object attributes = mock(Object.class); when(operationExecutor.execute(any(ExecutionContext.class))) .thenReturn(just(builder().output(payload).mediaType(mediaType).attributes(attributes).build())); Message message = (Message) messageProcessor.process(event).getVariables().get(TARGET_VAR).getValue(); assertThat(message, is(notNullValue())); assertThat(message.getPayload().getValue(), is(sameInstance(payload))); assertThat(message.getAttributes().getValue(), is(sameInstance(attributes))); assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType)); }
/** * Creates a new instance * * @param componentModel the component which produces the return value * @param cursorProviderFactory the {@link CursorProviderFactory} to use when a message is doing cursor based streaming. Can be * {@code null} * @param muleContext the {@link MuleContext} of the owning application */ protected AbstractReturnDelegate(ComponentModel componentModel, CursorProviderFactory cursorProviderFactory, MuleContext muleContext) { if (componentModel instanceof HasOutputModel) { HasOutputModel hasOutputModel = (HasOutputModel) componentModel; returnsListOfMessages = returnsListOfMessages(hasOutputModel); MetadataType outputType = hasOutputModel.getOutput().getType(); if (isMap(outputType)) { isSpecialHandling = true; returnHandler = new MapReturnHandler(hasOutputModel); } else if (isJavaCollection(outputType)) { isSpecialHandling = true; returnHandler = new CollectionReturnHandler(outputType); } } this.muleContext = muleContext; this.cursorProviderFactory = cursorProviderFactory; defaultEncoding = getDefaultEncoding(muleContext); defaultMediaType = getDefaultMediaType(componentModel); }
@Test public void operationReturnsOperationResultButKeepsAttributes() throws Exception { Object payload = new Object(); MediaType mediaType = ANY.withCharset(getDefaultEncoding(context)); when(operationExecutor.execute(any(ExecutionContext.class))) .thenReturn(just(builder().output(payload).mediaType(mediaType).build())); event = CoreEvent.builder(event).message(Message.builder().value("").attributesValue(mock(Object.class)).build()).build(); Message message = messageProcessor.process(event).getMessage(); assertThat(message, is(notNullValue())); assertThat(message.getPayload().getValue(), is(sameInstance(payload))); assertThat(message.getAttributes().getValue(), is(nullValue())); assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType)); }
@Test public void testAddVariableWithMimeType() throws MimeTypeParseException, MuleException { addVariableProcessor.setIdentifier(PLAIN_STRING_KEY); addVariableProcessor.setValue(PLAIN_STRING_VALUE); addVariableProcessor.initialise(); addVariableProcessor.setReturnDataType(DataType.builder().mediaType(APPLICATION_XML).build()); event = addVariableProcessor.process(event); verifyAdded(event, PLAIN_STRING_KEY, PLAIN_STRING_VALUE); assertThat(getVariableDataType(event, PLAIN_STRING_KEY), like(String.class, APPLICATION_XML, getDefaultEncoding(mockMuleContext))); }
private Transformer getIncreaseByOneTransformer() throws Exception { AbstractTransformer transformer = new AbstractTransformer() { @Override protected Object doTransform(Object src, Charset encoding) throws TransformerException { return new Integer(((Integer) src).intValue() + 1); } }; DataType integerDataType = DataType.fromType(Integer.class); transformer.registerSourceType(integerDataType); transformer.setReturnDataType(DataType.builder(integerDataType).charset(getDefaultEncoding(muleContext)).build()); return transformer; }
@Test public void operationReturnsOperationResultButKeepsAttributes() throws Exception { Object payload = new Object(); MediaType mediaType = ANY.withCharset(getDefaultEncoding(muleContext)); CoreEvent result = delegate.asReturnValue(Result.builder().output(payload).mediaType(mediaType).build(), operationContext); Message message = getOutputMessage(result); assertThat(message.getPayload().getValue(), is(sameInstance(payload))); assertThat(message.getAttributes().getValue(), is(nullValue())); assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType)); }
.encoding(getDefaultEncoding(muleContext)) .clientCredentials(authCodeConfig.getConsumerKey(), authCodeConfig.getConsumerSecret()) .tokenUrl(authCodeConfig.getAccessTokenUrl())
private Charset getEncoding(Object src) { if (src instanceof Message) { return ((Message) src).getPayload().getDataType().getMediaType().getCharset() .orElse(getDefaultEncoding(muleContext)); } else { return getDefaultEncoding(muleContext); } }