Hi, I had a lot of troubles with JndiContext in camel junit tests. I recognized that if you configure the jndiregistry in the unit test produced by CamelInitialContextFactory you'll always will get a new one if any library in between with do a new InitialContext() call. Thats why I created a simple threadsafe mock for easy use in unit tests.
Maybe anybody can create a jira issue and put it to trunk. I would consider adding to camel-test component fits best. Maybe a last minute change for 2.10.1? Best regards Benjamin
/** * 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.util.jndi; import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingException; /** * An InitialContext factory which allows multiple calls in unit tests. */ public class CamelInitialContextTestSupport extends CamelInitialContextFactory { private static volatile Context context; @Override public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { if (context != null) { return context; } return context = super.getInitialContext(environment); } }
signature.asc
Description: OpenPGP digital signature