blob: 844639206935ff3f8728a13563c084f5e7e5cca1 [file] [log] [blame]
/*
* Copyright (c) 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
*/
/*
* Client.java
*
* Created on February 21, 2003, 3:20 PM
*/
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import com.sun.ejte.ccl.reporter.SimpleReporterAdapter;
/**
*
* @author mvatkina
* @version
*/
public class Client {
private static test.BlobTestHome bhome = null;
private static SimpleReporterAdapter stat =
new SimpleReporterAdapter("appserv-tests");
public static void main(String[] args) {
boolean isJava2DBTest = args.length > 0;
try {
Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/RemoteBlobTest");
bhome =
(test.BlobTestHome) PortableRemoteObject.narrow(
objref, test.BlobTestHome.class);
System.out.println("START");
stat.addDescription("Blob");
test(100, "FOO", new byte[]{'A', 'B', 'C'});
test(200, "BAR", new byte[]{'M', 'N', 'O'});
test(300, null, new byte[]{'X', 'Y', 'Z'});
if (!isJava2DBTest) {
System.out.println("Testing old...");
test.BlobTest bean = bhome.findByPrimaryKey(new Integer(1));
System.out.println(new String(bean.getBlb()));
System.out.println(new String(bean.getByteblb()));
System.out.println(new String(bean.getByteblb2()));
} else {
try {
test(40, "BAZ", null);
stat.addStatus("ejbclient Blob", stat.FAIL);
throw new Exception(
"Failed to catch expected exception for insert of null blob value");
} catch (Exception ex) {
System.out.println(
"Caught expected exception when inserting null blob value");
//stat.addStatus("ejbclient Blob", stat.PASS);
}
}
stat.addStatus("ejbclient Blob", stat.PASS);
System.out.println("FINISH");
} catch (Exception ex) {
System.err.println("Caught an exception:");
ex.printStackTrace();
stat.addStatus("ejbclient Blob", stat.FAIL);
}
stat.printSummary("Blob");
}
static void test(int id, String name, byte chars[])
throws Exception {
Integer pk = new Integer(id);
test.BlobTest bean = bhome.create(pk, name, chars);
System.out.println("Created: " + bean.getPrimaryKey());
System.out.println("Testing new...");
bean = bhome.findByPrimaryKey(pk);
byte[] blb = bean.getBlb();
String blbString = blb == null ? "null" : new String(blb);
byte[] byteBlb = bean.getByteblb();
String byteBlbString = byteBlb == null ? "null" : new String(byteBlb);
byte[] byteBlb2 = bean.getByteblb2();
String byteBlb2String = byteBlb2 == null ? "null" : new String(byteBlb2);
System.out.println("blb=" + blbString);
System.out.println("byteblb=" + byteBlbString);
System.out.println("byteblb2=" + byteBlb2String);
}
}