View Javadoc

1   /*
2    * $Id: TestContextFactory.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.tck.jndi;
12  
13  import org.mule.tck.testmodels.fruit.Apple;
14  import org.mule.tck.testmodels.fruit.Banana;
15  import org.mule.tck.testmodels.fruit.Orange;
16  
17  import java.util.Hashtable;
18  
19  import javax.naming.Context;
20  import javax.naming.NamingException;
21  
22  /**
23   * Creates an in-memory context and populates it with test data.
24   */
25  public class TestContextFactory extends InMemoryContextFactory
26  {
27      public Context getInitialContext() throws NamingException
28      {
29          Context context = super.getInitialContext();
30          populateTestData(context);
31          return context;
32      }
33  
34      public Context getInitialContext(Hashtable environment) throws NamingException
35      {
36          Context context = super.getInitialContext(environment);
37          populateTestData(context);
38          return context;
39      }
40      
41      protected void populateTestData(Context context) throws NamingException
42      {
43          context.bind("fruit/apple", new Apple());
44          context.bind("fruit/banana", new Banana());
45          context.bind("fruit/orange", new Orange(new Integer(8), new Double(10), "Florida Sunny"));
46      }
47  }