<commit_before>/**
 *
 * 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.component.jms;

import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
import static org.apache.camel.component.mock.MockEndpoint.assertWait;

import java.util.concurrent.TimeUnit;

import javax.jms.ConnectionFactory;
import javax.jms.Session;

import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.DelegateProcessor;
import org.apache.camel.spi.Policy;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.spring.SpringRouteBuilder;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @version $Revision: 529902 $
 */
public class TransactedJmsRouteTest extends ContextTestSupport {
	
	private static final transient Log log = LogFactory.getLog(TransactedJmsRouteTest.class);
	private MockEndpoint mockEndpointA;
	private MockEndpoint mockEndpointB;
	private ClassPathXmlApplicationContext spring;
	private MockEndpoint mockEndpointC;
	private MockEndpoint mockEndpointD;

	@Override
	protected RouteBuilder createRouteBuilder() {
		return new SpringRouteBuilder() {
			public void configure() {
				
		        Policy requried = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_REQUIRED"));
		        Policy notsupported = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_NOT_SUPPORTED"));
		        Policy requirenew = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_REQUIRES_NEW"));

		        Policy rollback = new Policy() {
					public Processor wrap(Processor processor) {
						return new DelegateProcessor(processor) {
				        	@Override
				        	public void process(Exchange exchange) throws Exception {
				        		processNext(exchange);
				        		throw new RuntimeException("rollback");
				        	}
				        	
				        	@Override
				        	public String toString() {
				                return "rollback(" + this.processor + ")";
				        	}
				        };
					}
		        };
		        
		        Policy catchRollback = new Policy() {
					public Processor wrap(Processor processor) {
						return new DelegateProcessor(processor) {
				        	@Override
				        	public void process(Exchange exchange) {
				        		try {
				        			processNext(exchange);
				        		} catch ( Throwable e ) {
				        		}
				        	}
				        	@Override
				        	public String toString() {
				                return "catchRollback(" + this.processor + ")";
				        	}<commit_msg>added a Throttler implementation and test case for CAMEL-65. Also did some refactoring of the processors to increase the reuse and tidied up some test cases. Also some initial coding for CAMEL-66. Finally tided up the code a little<commit_after>/**
 *
 * 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.component.jms;

import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
import static org.apache.camel.component.mock.MockEndpoint.assertWait;

import java.util.concurrent.TimeUnit;

import javax.jms.ConnectionFactory;
import javax.jms.Session;

import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.DelegateProcessor;
import org.apache.camel.spi.Policy;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.spring.SpringRouteBuilder;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @version $Revision: 529902 $
 */
public class TransactedJmsRouteTest extends ContextTestSupport {
	
	private static final transient Log log = LogFactory.getLog(TransactedJmsRouteTest.class);
	private MockEndpoint mockEndpointA;
	private MockEndpoint mockEndpointB;
	private ClassPathXmlApplicationContext spring;
	private MockEndpoint mockEndpointC;
	private MockEndpoint mockEndpointD;

	@Override
	protected RouteBuilder createRouteBuilder() {
		return new SpringRouteBuilder() {
			public void configure() {
				
		        Policy requried = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_REQUIRED"));
		        Policy notsupported = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_NOT_SUPPORTED"));
		        Policy requirenew = new SpringTransactionPolicy(bean(TransactionTemplate.class, "PROPAGATION_REQUIRES_NEW"));

		        Policy rollback = new Policy() {
					public Processor wrap(Processor processor) {
						return new DelegateProcessor(processor) {
				        	@Override
				        	public void process(Exchange exchange) throws Exception {
				        		processNext(exchange);
				        		throw new RuntimeException("rollback");
				        	}
				        	
				        	@Override
				        	public String toString() {
				                return "rollback(" + getProcessor() + ")";
				        	}
				        };
					}
		        };
		        
		        Policy catchRollback = new Policy() {
					public Processor wrap(Processor processor) {
						return new DelegateProcessor(processor) {
				        	@Override
				        	public void process(Exchange exchange) {
				        		try {
				        			processNext(exchange);
				        		} catch ( Throwable e ) {
				        		}
				        	}
				        	@Override
				        	public String toString() {
				                return "catchRollback(" + this.processor + ")";
				        	}
{'fraction_non_alphanumeric': 0.07700101317122594, 'fraction_numerical': 0.00303951367781155, 'mean_word_length': 3.3318705430608886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '264286', 'n_tokens_mistral': 2268, 'n_tokens_neox': 1963, 'n_words': 580}