252N/A/*
252N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
252N/A *
252N/A * Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
252N/A *
252N/A * The contents of this file are subject to the terms of either the GNU
252N/A * General Public License Version 2 only ("GPL") or the Common Development
252N/A * and Distribution License("CDDL") (collectively, the "License"). You
252N/A * may not use this file except in compliance with the License. You can
252N/A * obtain a copy of the License at
252N/A * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
252N/A * or packager/legal/LICENSE.txt. See the License for the specific
252N/A * language governing permissions and limitations under the License.
252N/A *
252N/A * When distributing the software, include this License Header Notice in each
252N/A * file and include the License file at packager/legal/LICENSE.txt.
252N/A *
252N/A * GPL Classpath Exception:
252N/A * Oracle designates this particular file as subject to the "Classpath"
252N/A * exception as provided by Oracle in the GPL Version 2 section of the License
252N/A * file that accompanied this code.
252N/A *
252N/A * Modifications:
252N/A * If applicable, add the following below the License Header, with the fields
252N/A * enclosed by brackets [] replaced by your own identifying information:
252N/A * "Portions Copyright [year] [name of copyright owner]"
252N/A *
252N/A * Contributor(s):
252N/A * If you wish your version of this file to be governed by only the CDDL or
252N/A * only the GPL Version 2, indicate your decision by adding "[Contributor]
252N/A * elects to include this software in this distribution under the [CDDL or GPL
252N/A * Version 2] license." If you don't indicate a single choice of license, a
252N/A * recipient has the option to distribute your version of this file under
252N/A * either the CDDL, the GPL Version 2 or to extend the choice of license to
252N/A * its licensees as provided above. However, if you add GPL Version 2 code
252N/A * and therefore, elected the GPL Version 2 license, then the option applies
252N/A * only if the new code is made subject to such option by the copyright
252N/A * holder.
252N/A */
252N/A
252N/Apackage test.ejb.remoteview;
252N/A
252N/A
252N/Aimport org.testng.annotations.*;
252N/Aimport org.testng.Assert;
252N/Aimport javax.naming.InitialContext;
252N/Aimport java.util.concurrent.Future;
252N/Aimport java.util.concurrent.ExecutionException;
252N/Aimport remoteview.*;
252N/A
252N/Apublic class RemoteViewTestNG {
252N/A private String appName="remoteview";
252N/A
252N/A @Test(groups = { "init" })
252N/A public void helloRemote() throws Exception{
252N/A boolean test_result = false;
252N/A try {
252N/A HelloHome helloHome = (HelloHome) new InitialContext().lookup("java:global/" + appName + "/HelloBean!remoteview.HelloHome");
252N/A callHome(helloHome);
252N/A
252N/A Hello hello = (Hello) new InitialContext().lookup("HH#remoteview.Hello");
252N/A Future<String> future = hello.helloAsync();
252N/A hello.helloAsync();
252N/A hello.helloAsync();
252N/A hello.helloAsync();
252N/A hello.fireAndForget();
252N/A
252N/A String result = future.get();
252N/A //System.out.println("helloAsync() says : " + result);
252N/A test_result = true;
252N/A } catch(ExecutionException e) {
252N/A test_result = false;
252N/A System.out.println("Got async ExecutionException. Cause is " +
252N/A e.getCause().getMessage());
252N/A e.getCause().printStackTrace();
252N/A }
252N/A Assert.assertEquals(test_result, true,"Unexpected Results");
252N/A }
252N/A
252N/A @Test(dependsOnGroups = { "init.*" })
252N/A public void portableGlobal() throws Exception{
252N/A boolean test_result = false;
252N/A // Fully-qualified portable global
252N/A try{
252N/A HelloHome helloHome2 = (HelloHome) new InitialContext().lookup("java:global/" + appName + "/HelloBean!remoteview.HelloHome");
252N/A callHome(helloHome2);
252N/A
252N/A Hello hello2 = (Hello) new InitialContext().lookup("java:global/" + appName + "/HelloBean!remoteview.Hello");
252N/A callBusHome(hello2);
252N/A test_result = true;
252N/A } catch(Exception e) {
252N/A test_result = false;
252N/A System.out.println("Exception from portableGlobal:"+e);
252N/A }
252N/A Assert.assertEquals(test_result, true,"Unexpected Results");
252N/A }
252N/A
252N/A @Test(dependsOnGroups = { "init.*" })
252N/A public void nonPortableGlobal() throws Exception{
252N/A boolean test_result = false;
252N/A // non-portable global
252N/A try{
252N/A HelloHome helloHome5 = (HelloHome) new InitialContext().lookup("HH");
252N/A callHome(helloHome5);
252N/A
252N/A Hello hello5 = (Hello) new InitialContext().lookup("HH#remoteview.Hello");
252N/A callBusHome(hello5);
252N/A test_result = true;
252N/A } catch(Exception e) {
252N/A test_result = false;
252N/A System.out.println("Exception from portableGlobal:"+e);
252N/A }
252N/A Assert.assertEquals(test_result, true,"Unexpected Results");
252N/A }
252N/A
252N/A private static void callHome(HelloHome home) throws Exception {
252N/A HelloRemote hr = home.create();
252N/A //System.out.println("2.x HelloRemote.hello() says " + hr.hello());
252N/A }
252N/A private static void callBusHome(Hello h) {
252N/A String hret = h.hello();
252N/A //System.out.println("Hello.hello() says " + h.hello());
252N/A }
252N/A}
252N/A