blob: 5b7a076e889de939d70f0f4a7924ec3cc051834a [file] [log] [blame]
Vinay Vishal57171472018-09-18 20:22:00 +05301/*
2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
13 *
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15 */
16
17package com.acme;
18
19import org.glassfish.tests.ejb.timertest.SimpleEjb;
20
21import java.util.Map;
22import java.util.HashMap;
23import javax.ejb.*;
24import javax.ejb.embeddable.EJBContainer;
25import javax.naming.Context;
26import javax.naming.NamingException;
27
28import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
29
30public class Client {
31
32 private static SimpleReporterAdapter stat =
33 new SimpleReporterAdapter("appserv-tests");
34
35 private static String appName;
36
37 public static void main(String[] s) {
38 appName = s[0];
39 System.err.println(".......... Testing module: " + appName);
40 stat.addDescription(appName);
41 Client t = new Client();
42 try {
43 t.test(appName, 1);
44 } catch (Exception e) {
45 stat.addStatus("EJB embedded with timertest 1", stat.FAIL);
46 e.printStackTrace();
47 }
48 System.err.println("------------------------");
49 if (s.length == 2 && s[1].equals("false")) {
50 System.err.println("-------This part of the test will fail if ran against Full Profile ------------");
51 try {
52 t.test(appName, 2);
53 } catch (Exception e) {
54 stat.addStatus("EJB embedded with timertest 2", stat.FAIL);
55 e.printStackTrace();
56 }
57 System.err.println("------------------------");
58 } else {
59 System.err.println("-------Do not run 2nd time until timer app reload is fixed ------------");
60 }
61 stat.printSummary(appName + "ID");
62 System.exit(0);
63 }
64
65 private void test(String module, int id) {
66
67 EJBContainer c = EJBContainer.createEJBContainer();
68 // ok now let's look up the EJB...
69 Context ic = c.getContext();
70 try {
71 System.err.println("Looking up EJB...");
72 SimpleEjb ejb = (SimpleEjb) ic.lookup("java:global/" + module + "/SimpleEjb");
73 System.err.println("Invoking EJB...");
74 ejb.createTimer();
75 Thread.sleep(8000);
76 boolean result = ejb.verifyTimer();
77 System.err.println("EJB timer called: " + result);
78 if (!result)
79 throw new Exception ("EJB timer was NOT called for 1 or 2 timers");
80
81 stat.addStatus("EJB embedded with timertest" + id, stat.PASS);
82 } catch (Exception e) {
83 stat.addStatus("EJB embedded with timertest" + id, stat.FAIL);
84 System.err.println("ERROR calling EJB:");
85 e.printStackTrace();
86 } finally {
87 c.close();
88 }
89 System.err.println("Done calling EJB");
90 }
91
92}