Package org.apache.openejb.config

Source Code of org.apache.openejb.config.MappedNameTest$GreenBean

/**
* 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.openejb.config;

import junit.framework.TestCase;
import org.apache.openejb.core.LocalInitialContextFactory;
import org.apache.openejb.assembler.classic.Assembler;
import org.apache.openejb.assembler.classic.TransactionServiceInfo;
import org.apache.openejb.assembler.classic.SecurityServiceInfo;
import org.apache.openejb.assembler.classic.EjbJarInfo;
import org.apache.openejb.jee.EjbJar;
import org.apache.openejb.jee.StatelessBean;
import org.apache.openejb.jee.oejb3.OpenejbJar;
import org.apache.openejb.jee.oejb3.EjbDeployment;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
* @version $Rev: 1227481 $ $Date: 2012-01-04 20:39:55 -0800 (Wed, 04 Jan 2012) $
*/
public class MappedNameTest extends TestCase {

    public void test() throws Exception {
        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());

        ConfigurationFactory config = new ConfigurationFactory();
        Assembler assembler = new Assembler();

        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

        EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(GreenBean.class));
        ejbJar.addEnterpriseBean(new StatelessBean(RedBean.class));

        EjbModule ejbModule = new EjbModule(ejbJar, new OpenejbJar());

        ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Green", "GreenBean"));
        ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Red", "RedBean"));

        EjbJarInfo info = config.configureApplication(ejbModule);
        assembler.createApplication(info);

        InitialContext initialContext = new InitialContext();
        Color green = (Color) initialContext.lookup("foo/bar/baz/GreenLocal");
        Color red = (Color) initialContext.lookup("foo/bar/baz/RedLocal");

        red.test();
    }

    public static interface Color {

        public void test() throws NamingException;

    }

    public static class GreenBean implements Color {
        public void test() throws NamingException {
        }
    }

    @EJB(name = "green", beanName = "GreenBean", beanInterface = Color.class)
    public static class RedBean implements Color {

        public void test() throws NamingException {
            InitialContext initialContext = new InitialContext();
            initialContext.lookup("java:comp/env/green");
        }
    }
}
TOP

Related Classes of org.apache.openejb.config.MappedNameTest$GreenBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.