blob: 505d64ca9ee64068274b489b55f29c12c3e76d71 [file] [log] [blame]
/*
* Copyright (c) 2001, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.s1peqe.ejb.bmp.enroller.client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import com.sun.s1peqe.ejb.bmp.enroller.ejb.*;
import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
/**
* A simple java client will:
* <ul>
* <li>Locates the home interface of the enterprise bean
* <li>Gets a reference to the remote interface
* <li>Invokes business methods
* </ul>
*/
public class EnrollerClient {
private SimpleReporterAdapter stat =
new SimpleReporterAdapter("appserv-tests");
public static void main(String[] args) {
EnrollerClient client = new EnrollerClient();
// run the tests
client.runTestClient();
}
public void runTestClient() {
try{
stat.addDescription("Testing bmp enroller app.");
test01();
stat.printSummary("enrollerAppID");
} catch (Exception ex) {
System.out.println("Exception in runTestClient: " + ex.toString());
ex.printStackTrace();
}
}
private void test01() {
try {
Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/SimpleStudent");
StudentHome sHome =
(StudentHome) PortableRemoteObject.narrow(objref,
StudentHome.class);
Student denise = sHome.create("823", "Denise Smith");
objref = initial.lookup("java:comp/env/ejb/SimpleCourse");
CourseHome cHome =
(CourseHome) PortableRemoteObject.narrow(objref,
CourseHome.class);
Course power = cHome.create("220", "Power J2EE Programming");
objref = initial.lookup("java:comp/env/ejb/SimpleEnroller");
EnrollerHome eHome =
(EnrollerHome) PortableRemoteObject.narrow(objref,
EnrollerHome.class);
Enroller enroller = eHome.create();
enroller.enroll("823", "220");
enroller.enroll("823", "333");
enroller.enroll("823", "777");
enroller.enroll("456", "777");
enroller.enroll("388", "777");
System.out.println(denise.getName() + ":");
ArrayList courses = denise.getCourseIds();
Iterator i = courses.iterator();
while (i.hasNext()) {
String courseId = (String)i.next();
Course course = cHome.findByPrimaryKey(courseId);
System.out.println(courseId + " " + course.getName());
}
System.out.println();
Course intro = cHome.findByPrimaryKey("777");
System.out.println(intro.getName() + ":");
courses = intro.getStudentIds();
i = courses.iterator();
while (i.hasNext()) {
String studentId = (String)i.next();
Student student = sHome.findByPrimaryKey(studentId);
System.out.println(studentId + " " + student.getName());
}
stat.addStatus("enroller bmp", stat.PASS);
} catch (Exception ex) {
stat.addStatus("enroller bmp", stat.FAIL);
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}