http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/main/resources/gdsl/CamelGroovyMethods.gdsl ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/main/resources/gdsl/CamelGroovyMethods.gdsl b/components/camel-groovy/src/main/resources/gdsl/CamelGroovyMethods.gdsl deleted file mode 100644 index eac8545..0000000 --- a/components/camel-groovy/src/main/resources/gdsl/CamelGroovyMethods.gdsl +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*******************************************************************************/ -contributor([context(ctype: 'org.apache.camel.model.ProcessorDefinition')]) { - method name: 'process', type: 'org.apache.camel.model.ProcessorDefinition', params: [processorLogic: 'groovy.lang.Closure'] - method name: 'enrich', type: 'org.apache.camel.model.ProcessorDefinition', params: [resourceUri: 'java.lang.String', aggregationLogic: 'groovy.lang.Closure'] - method name: 'pollEnrich', type: 'org.apache.camel.model.ProcessorDefinition', params: [resourceUri: 'java.lang.String', aggregationLogic: 'groovy.lang.Closure'] - method name: 'pollEnrich', type: 'org.apache.camel.model.ProcessorDefinition', params: [resourceUri: 'java.lang.String', timeout: 'long', aggregationLogic: 'groovy.lang.Closure'] - method name: 'script', type: 'org.apache.camel.model.ProcessorDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'transform', type: 'org.apache.camel.model.ProcessorDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'setProperty', type: 'org.apache.camel.model.ProcessorDefinition', params: [name: 'java.lang.String', expression: 'groovy.lang.Closure'] - method name: 'setHeader', type: 'org.apache.camel.model.ProcessorDefinition', params: [name: 'java.lang.String', expression: 'groovy.lang.Closure'] - method name: 'setBody', type: 'org.apache.camel.model.ProcessorDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'setFaultBody', type: 'org.apache.camel.model.ProcessorDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'sort', type: 'org.apache.camel.model.ProcessorDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'idempotentConsumer', type: 'org.apache.camel.model.IdempotentConsumerDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'idempotentConsumer', type: 'org.apache.camel.model.IdempotentConsumerDefinition', params: [rep: 'org.apache.camel.spi.IdempotentRepository', expression: 'groovy.lang.Closure'] - method name: 'recipientList', type: 'org.apache.camel.model.RecipientListDefinition', params: [recipients: 'groovy.lang.Closure'] - method name: 'recipientList', type: 'org.apache.camel.model.RecipientListDefinition', params: [delimiter: 'java.lang.String', recipients: 'groovy.lang.Closure'] - method name: 'routingSlip', type: 'org.apache.camel.model.RoutingSlipDefinition', params: [recipients: 'groovy.lang.Closure'] - method name: 'routingSlip', type: 'org.apache.camel.model.RoutingSlipDefinition', params: [delimiter: 'java.lang.String', recipients: 'groovy.lang.Closure'] - method name: 'dynamicRouter', type: 'org.apache.camel.model.DynamicRouterDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'split', type: 'org.apache.camel.model.SplitDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'resequence', type: 'org.apache.camel.model.ResequenceDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'aggregate', type: 'org.apache.camel.model.AggregateDefinition', params: [correlationExpression: 'groovy.lang.Closure'] - method name: 'delay', type: 'org.apache.camel.model.DelayDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'throttle', type: 'org.apache.camel.model.ThrottleDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'loop', type: 'org.apache.camel.model.LoopDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'filter', type: 'org.apache.camel.model.FilterDefinition', params: [predicate: 'groovy.lang.Closure'] - method name: 'validate', type: 'org.apache.camel.model.ProcessorDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.groovy.extend.CamelGroovyMethods')]) { - method name: 'newExchange', type: 'org.apache.camel.model.WireTapDefinition', params: [self: 'org.apache.camel.model.WireTapDefinition', processorLogic: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.OnExceptionDefinition')]) { - method name: 'onRedelivery', type: 'org.apache.camel.model.OnExceptionDefinition', params: [processorLogic: 'groovy.lang.Closure'] - method name: 'onWhen', type: 'org.apache.camel.model.OnExceptionDefinition', params: [predicate: 'groovy.lang.Closure'] - method name: 'handled', type: 'org.apache.camel.model.OnExceptionDefinition', params: [predicate: 'groovy.lang.Closure'] - method name: 'continued', type: 'org.apache.camel.model.OnExceptionDefinition', params: [predicate: 'groovy.lang.Closure'] - method name: 'retryWhile', type: 'org.apache.camel.model.OnExceptionDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.MulticastDefinition')]) { - method name: 'aggregationStrategy', type: 'org.apache.camel.model.MulticastDefinition', params: [aggregationLogic: 'groovy.lang.Closure'] - method name: 'onPrepare', type: 'org.apache.camel.model.MulticastDefinition', params: [processorLogic: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.RecipientListDefinition')]) { - method name: 'aggregationStrategy', type: 'org.apache.camel.model.RecipientListDefinition', params: [aggregationLogic: 'groovy.lang.Closure'] - method name: 'onPrepare', type: 'org.apache.camel.model.RecipientListDefinition', params: [processorLogic: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.SplitDefinition')]) { - method name: 'aggregationStrategy', type: 'org.apache.camel.model.SplitDefinition', params: [aggregationLogic: 'groovy.lang.Closure'] - method name: 'onPrepare', type: 'org.apache.camel.model.SplitDefinition', params: [processorLogic: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.AggregateDefinition')]) { - method name: 'aggregationStrategy', type: 'org.apache.camel.model.AggregateDefinition', params: [aggregationLogic: 'groovy.lang.Closure'] - method name: 'completionSize', type: 'org.apache.camel.model.AggregateDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'completionTimeout', type: 'org.apache.camel.model.AggregateDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'completionPredicate', type: 'org.apache.camel.model.AggregateDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.WireTapDefinition')]) { - method name: 'onPrepare', type: 'org.apache.camel.model.WireTapDefinition', params: [processorLogic: 'groovy.lang.Closure'] - method name: 'newExchangeBody', type: 'org.apache.camel.model.WireTapDefinition', params: [expression: 'groovy.lang.Closure'] - method name: 'newExchangeHeader', type: 'org.apache.camel.model.WireTapDefinition', params: [header: 'java.lang.String', expression: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.ChoiceDefinition')]) { - method name: 'when', type: 'org.apache.camel.model.ChoiceDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.TryDefinition')]) { - method name: 'onWhen', type: 'org.apache.camel.model.TryDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.OnCompletionDefinition')]) { - method name: 'onWhen', type: 'org.apache.camel.model.OnCompletionDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.CatchDefinition')]) { - method name: 'onWhen', type: 'org.apache.camel.model.CatchDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.InterceptDefinition')]) { - method name: 'when', type: 'org.apache.camel.model.InterceptDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.model.InterceptSendToEndpointDefinition')]) { - method name: 'when', type: 'org.apache.camel.model.InterceptSendToEndpointDefinition', params: [predicate: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.builder.RouteBuilder')]) { - method name: 'aggregator', type: 'org.apache.camel.processor.aggregate.AggregationStrategy', params: [aggregationLogic: 'groovy.lang.Closure'] - method name: 'expression', type: 'org.apache.camel.Expression', params: [expression: 'groovy.lang.Closure'] - method name: 'predicate', type: 'org.apache.camel.Predicate', params: [predicate: 'groovy.lang.Closure'] - method name: 'processor', type: 'org.apache.camel.Processor', params: [processor: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.builder.ExpressionClause')]) { - method name: 'expression', type: 'T', params: [expression: 'groovy.lang.Closure'] -} -contributor([context(ctype: 'org.apache.camel.builder.DataFormatClause')]) { - method name: 'gnode', type: 'org.apache.camel.model.ProcessorDefinition', params: [namespaceAware: 'boolean'] - method name: 'gnode', type: 'org.apache.camel.model.ProcessorDefinition' - method name: 'gpath', type: 'org.apache.camel.model.ProcessorDefinition', params: [namespaceAware: 'boolean'] - method name: 'gpath', type: 'org.apache.camel.model.ProcessorDefinition' -}
http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/main/resources/org/apache/camel/language/groovy/ConfigureCamel.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/main/resources/org/apache/camel/language/groovy/ConfigureCamel.groovy b/components/camel-groovy/src/main/resources/org/apache/camel/language/groovy/ConfigureCamel.groovy deleted file mode 100644 index 9f135f8..0000000 --- a/components/camel-groovy/src/main/resources/org/apache/camel/language/groovy/ConfigureCamel.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.language.groovy - -import org.apache.camel.model.ChoiceDefinition; -import org.apache.camel.model.ProcessorDefinition; - -/** - */ -class ConfigureCamel implements Runnable { - - static void main(String[] args) { - new ConfigureCamel().run(); - } - - void run() { - ExpandoMetaClass.enableGlobally(); - - ProcessorDefinition.metaClass.filter = { filter -> - if (filter instanceof Closure) { - filter = CamelGroovyMethods.toExpression(filter) - } - delegate.filter(filter); - } - - ChoiceDefinition.metaClass.when = { filter -> - if (filter instanceof Closure) { - filter = CamelGroovyMethods.toExpression(filter) - } - delegate.when(filter); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy deleted file mode 100644 index a96fbfd..0000000 --- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.groovy.converter - -import groovy.util.slurpersupport.GPathResult -import org.apache.camel.CamelContext -import org.apache.camel.Exchange -import org.apache.camel.StringSource -import org.apache.camel.impl.DefaultCamelContext -import org.apache.camel.impl.DefaultExchange -import org.junit.Test -import org.w3c.dom.Node -import org.xml.sax.InputSource - -import javax.xml.parsers.DocumentBuilderFactory - -import static org.junit.Assert.assertEquals -import static org.junit.Assert.assertNotNull - -public class GPathResultConverterTest { - String xml = "<test><elem1>This is test</elem1></test>" - CamelContext context = new DefaultCamelContext() - - @Test - void "should convert string to GPathResult"() { - Exchange exchange = new DefaultExchange(context) - exchange.in.setBody(xml, String) - GPathResult result = exchange.in.getBody(GPathResult) - checkGPathResult(result) - } - - @Test - void "should convert string source to GPathResult"() { - StringSource input = new StringSource(xml) - Exchange exchange = new DefaultExchange(context) - exchange.in.setBody(input, StringSource) - GPathResult result = exchange.in.getBody(GPathResult) - checkGPathResult(result) - } - - @Test - void "should convert node to GPathResult"() { - Node node = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(new InputSource(new StringReader(xml))) - Exchange exchange = new DefaultExchange(context) - exchange.in.setBody(node, Node) - GPathResult result = exchange.in.getBody(GPathResult) - checkGPathResult(result) - } - - private void checkGPathResult(GPathResult gPathResult) { - assertNotNull(gPathResult) - assertEquals(gPathResult.name(), "test") - assertEquals(gPathResult.elem1.text(), "This is test") - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/CamelGroovyMethodsTest.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/CamelGroovyMethodsTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/CamelGroovyMethodsTest.groovy deleted file mode 100644 index 2766892..0000000 --- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/CamelGroovyMethodsTest.groovy +++ /dev/null @@ -1,244 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.groovy.extend - -import org.apache.camel.EndpointInject -import org.apache.camel.Exchange -import org.apache.camel.builder.RouteBuilder -import org.apache.camel.component.mock.MockEndpoint -import org.apache.camel.test.junit4.CamelTestSupport -import org.junit.Test - -/** - * Test a few DSL extensions. - */ -class CamelGroovyMethodsTest extends CamelTestSupport { - - private static final String HELLO = 'Hello' - private static final String WORLD = 'World' - - @EndpointInject(uri = 'mock:test1') - private MockEndpoint resultEndpoint; - @EndpointInject(uri = 'mock:test2') - private MockEndpoint otherEndpoint; - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - - def aggregation = { Exchange original, Exchange resource -> - original.in.body += resource.in.body - original - } - - return new RouteBuilder() { - - @Override - public void configure() throws Exception { - - from('direct:test1') - .enrich('direct:enrich') { Exchange original, Exchange resource -> - original.in.body += resource.in.body - original - } - .to('mock:test1') - - from('direct:enrich') - .transform(constant(WORLD)) - - from('direct:test2') - .pollEnrich('seda:enrich', aggregation) - .to('mock:test1') - - from('direct:test3') - .process { Exchange e -> - e.in.with { - body = HELLO - headers[HELLO] = WORLD - } - } - .to('mock:test1') - - from('direct:test4') - .setHeader(HELLO) { Exchange e -> - e.in.body.reverse() - } - .to('mock:test1') - - from('direct:test5') - .setProperty(HELLO) { Exchange e -> - e.in.body.reverse() - } - .to('mock:test1') - - from('direct:test6') - .transform { Exchange e -> - e.in.body.reverse() - } - .to('mock:test1') - - from('direct:test7') - .setBody { Exchange e -> - e.in.body.reverse() - } - .to('mock:test1') - - from('direct:test8') - .unmarshal().gpath() - // XmlSlurper proceeds to first node - .transform { it.in.body.World.text() } - .to('mock:test1') - - from('direct:test9') - .unmarshal().gnode() - // XmlParser proceeds to first node - .transform { it.in.body.World.text() } - .to('mock:test1') - - from('direct:test10') - .marshal().gnode() - .convertBodyTo(String) - .to('mock:test1') - - from('direct:test11') - .choice() - .when { it.in.body == HELLO }.to('mock:test1') - .otherwise().to('mock:test2') - - from('direct:test12') - .setHeader(HELLO).expression { Exchange e -> - e.in.body.reverse() - } - .to('mock:test1') - - from('direct:toD') - .toD('mock:${header.foo}') - - } - - } - } - - @Test - void testClosureEnricherAggregation() { - resultEndpoint.expectedBodiesReceived(HELLO + WORLD) - template.sendBody('direct:test1', HELLO) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosurePollingEnricherAggregation() { - resultEndpoint.expectedBodiesReceived(HELLO + WORLD) - template.sendBody('seda:enrich', WORLD) - template.sendBody('direct:test2', HELLO) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureProcessor() { - resultEndpoint.expectedBodiesReceived(HELLO) - resultEndpoint.expectedHeaderReceived(HELLO, WORLD) - template.sendBody('direct:test3', '') - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureSetHeader() { - resultEndpoint.expectedHeaderReceived(HELLO, WORLD) - template.sendBody('direct:test4', WORLD.reverse()) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureSetHeaderWithExpressionClause() { - resultEndpoint.expectedHeaderReceived(HELLO, WORLD) - template.sendBody('direct:test4', WORLD.reverse()) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureSetProperty() { - resultEndpoint.expectedPropertyReceived(HELLO, WORLD) - template.sendBody('direct:test5', WORLD.reverse()) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureTransformer() { - resultEndpoint.expectedBodiesReceived(HELLO) - template.sendBody('direct:test6', HELLO.reverse()) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureSetBody() { - resultEndpoint.expectedBodiesReceived(HELLO) - template.sendBody('direct:test7', HELLO.reverse()) - resultEndpoint.assertIsSatisfied() - } - - @Test - void testClosureChoice1() { - resultEndpoint.expectedBodiesReceived(HELLO) - otherEndpoint.expectedMessageCount(0) - template.sendBody('direct:test11', HELLO) - resultEndpoint.assertIsSatisfied() - otherEndpoint.assertIsSatisfied() - } - - @Test - void testClosureChoice2() { - resultEndpoint.expectedMessageCount(0) - otherEndpoint.expectedBodiesReceived(WORLD) - template.sendBody('direct:test11', WORLD) - resultEndpoint.assertIsSatisfied() - otherEndpoint.assertIsSatisfied() - } - - @Test - void testXmlSlurper() { - String text = "How are you?" - resultEndpoint.expectedBodiesReceived(text) - template.sendBody('direct:test8', "<Hello><World>${text}</World></Hello>") - resultEndpoint.assertIsSatisfied() - } - - @Test - void testXmlParser() { - String text = "How are you?" - resultEndpoint.expectedBodiesReceived(text) - template.sendBody('direct:test9', "<Hello><World>${text}</World></Hello>") - resultEndpoint.assertIsSatisfied() - } - - @Test - void testXmlPrinter() { - String text = "<Hello><World>How are you?</World></Hello>" - Node parsed = new XmlParser().parseText(text) - resultEndpoint.expectedMessageCount(1) - template.sendBody('direct:test10', parsed) - // The created XML differs in terms of white spaces and line feeds. - assertEquals(text.replaceAll('\\s+', ''), resultEndpoint.exchanges[0].in.body.replaceAll('\\s+', '')) - } - - @Test - void testToD() { - resultEndpoint.expectedMessageCount(1) - template.sendBodyAndHeader('direct:toD', WORLD, "foo", "test1") - resultEndpoint.assertIsSatisfied() - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureAggregationStrategyTest.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureAggregationStrategyTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureAggregationStrategyTest.groovy deleted file mode 100644 index 71a9b73..0000000 --- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureAggregationStrategyTest.groovy +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.groovy.extend - -import static org.junit.Assert.* -import static org.apache.camel.groovy.extend.CamelGroovyMethods.toAggregationStrategy - -import org.apache.camel.CamelContext -import org.apache.camel.Exchange -import org.apache.camel.impl.DefaultCamelContext -import org.apache.camel.impl.DefaultExchange -import org.junit.Before -import org.junit.Test - - -class ClosureAggregationStrategyTest { - - private Exchange exchange1 - private Exchange exchange2 - private static final String HELLO = "Hello" - private static final String WORLD = "World" - - @Before - public void setUp() throws Exception { - CamelContext context = new DefaultCamelContext() - exchange1 = new DefaultExchange(context); - exchange2 = new DefaultExchange(context); - } - - @Test - public void testAggregationStrategy() { - exchange1.in.body = HELLO - exchange2.in.body = WORLD - ClosureAggregationStrategy cas = toAggregationStrategy { Exchange oldExchange, Exchange newExchange -> - newExchange.in.body = newExchange.in.body + ' ' + oldExchange.in.body - newExchange - } - assertEquals(HELLO + ' ' + WORLD, cas.aggregate(exchange2, exchange1).in.body) - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureExpressionTest.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureExpressionTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureExpressionTest.groovy deleted file mode 100644 index ecd50a2..0000000 --- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureExpressionTest.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.groovy.extend - -import static org.junit.Assert.* -import static org.apache.camel.groovy.extend.CamelGroovyMethods.toExpression - -import org.apache.camel.Exchange -import org.apache.camel.impl.DefaultCamelContext -import org.apache.camel.impl.DefaultExchange -import org.junit.Before -import org.junit.Test - - -class ClosureExpressionTest { - - private Exchange exchange - private static final String HELLO = "Hello" - - @Before - public void setUp() throws Exception { - exchange = new DefaultExchange(new DefaultCamelContext()); - exchange.in.body = HELLO - } - - @Test - public void testAsExpression() { - ClosureExpression expression = toExpression { Exchange exchange -> - exchange.in.body - } - assertEquals(HELLO, expression.evaluate(exchange)) - } - - @Test - public void testAsPredicate() { - ClosureExpression expressionTrue = toExpression { Exchange exchange -> - exchange.in.body == HELLO - } - assertTrue(expressionTrue.evaluate(exchange)) - ClosureExpression expressionFalse = toExpression { Exchange exchange -> - exchange.in.body != HELLO - } - assertFalse(expressionFalse.evaluate(exchange)) - } - - @Test - public void testClosureException() { - String unknownProperty = 'Gablorg' - ClosureExpression expression = toExpression { Exchange exchange -> - exchange."${unknownProperty}" - } - try { - expression.evaluate(exchange) - } catch (MissingPropertyException e) { - assertTrue(e.message.contains(unknownProperty)) - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureProcessorTest.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureProcessorTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureProcessorTest.groovy deleted file mode 100644 index 3733551..0000000 --- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/extend/ClosureProcessorTest.groovy +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.groovy.extend - -import static org.junit.Assert.* -import static org.apache.camel.groovy.extend.CamelGroovyMethods.toProcessor - -import org.apache.camel.Exchange -import org.apache.camel.impl.DefaultCamelContext -import org.apache.camel.impl.DefaultExchange -import org.junit.Before -import org.junit.Test - - -class ClosureProcessorTest { - - private Exchange exchange - private static final String HELLO = "Hello" - - @Before - public void setUp() throws Exception { - exchange = new DefaultExchange(new DefaultCamelContext()); - } - - @Test - public void testProcessor() { - exchange.in.body = HELLO - ClosureProcessor processor = toProcessor { Exchange exchange -> - exchange.in.body = exchange.in.body.reverse() - } - processor.process(exchange) - assertEquals(HELLO.reverse(), exchange.in.body ) - } - - @Test(expected=NullPointerException) - public void testProcessorException() { - exchange.in.body = null - ClosureProcessor processor = toProcessor { Exchange exchange -> - exchange.in.body = exchange.in.body.reverse() - } - processor.process(exchange) - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyExpressionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyExpressionTest.java b/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyExpressionTest.java index 37d5d66..1e3efe9 100644 --- a/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyExpressionTest.java +++ b/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyExpressionTest.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; * @version */ public class GroovyExpressionTest extends CamelTestSupport { - private static final Logger LOG = LoggerFactory.getLogger(GroovyTest.class); + private static final Logger LOG = LoggerFactory.getLogger(GroovyExpressionTest.class); protected Exchange exchange; http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyTest.java b/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyTest.java deleted file mode 100644 index ed5b932..0000000 --- a/components/camel-groovy/src/test/java/org/apache/camel/language/groovy/GroovyTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.language.groovy; - -import groovy.lang.GroovyClassLoader; -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -/** - * @version - */ -public class GroovyTest extends CamelTestSupport { - protected String expected = "<hello>world!</hello>"; - protected String groovyBuilderClass = "org.apache.camel.language.groovy.example.GroovyRoutes"; - - @Test - public void testSendMatchingMessage() throws Exception { - MockEndpoint resultEndpoint = getMockEndpoint("mock:results"); - resultEndpoint.expectedBodiesReceived(expected); - - template.sendBodyAndHeader("direct:a", expected, "foo", "bar"); - - assertMockEndpointsSatisfied(); - - log.debug("Should have received one exchange: " + resultEndpoint.getReceivedExchanges()); - } - - @Test - public void testSendNotMatchingMessage() throws Exception { - MockEndpoint resultEndpoint = getMockEndpoint("mock:results"); - resultEndpoint.expectedMessageCount(0); - - template.sendBodyAndHeader("direct:a", expected, "foo", "123"); - - assertMockEndpointsSatisfied(); - - log.debug("Should not have received any messages: " + resultEndpoint.getReceivedExchanges()); - } - - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext answer = super.createCamelContext(); - - GroovyClassLoader classLoader = new GroovyClassLoader(); - Class<?> type = classLoader.loadClass(groovyBuilderClass); - Object object = answer.getInjector().newInstance(type); - RouteBuilder builder = assertIsInstanceOf(RouteBuilder.class, object); - - log.info("Loaded builder: " + builder); - answer.addRoutes(builder); - - return answer; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/91ff7db2/components/camel-groovy/src/test/resources/org/apache/camel/language/groovy/example/GroovyRoutes.groovy ---------------------------------------------------------------------- diff --git a/components/camel-groovy/src/test/resources/org/apache/camel/language/groovy/example/GroovyRoutes.groovy b/components/camel-groovy/src/test/resources/org/apache/camel/language/groovy/example/GroovyRoutes.groovy deleted file mode 100644 index e1b5c5e..0000000 --- a/components/camel-groovy/src/test/resources/org/apache/camel/language/groovy/example/GroovyRoutes.groovy +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.language.groovy.example - -import org.apache.camel.language.groovy.GroovyRouteBuilder; - -class GroovyRoutes extends GroovyRouteBuilder { - - void configure() { - - from("direct:a").filter {e -> - e.in.headers.foo == "bar" - }.to("mock:results") - - } -} \ No newline at end of file