Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/activation/ActivationGroupIDTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/activation/ActivationGroupIDTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/activation/ActivationGroupIDTest.java (revision 0) @@ -0,0 +1,187 @@ +/* + * 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.harmony.rmi.tests.java.rmi.activation; + +import java.rmi.RemoteException; +import java.rmi.activation.ActivationDesc; +import java.rmi.activation.ActivationException; +import java.rmi.activation.ActivationGroup; +import java.rmi.activation.ActivationGroupDesc; +import java.rmi.activation.ActivationGroupID; +import java.rmi.activation.ActivationID; +import java.rmi.activation.ActivationInstantiator; +import java.rmi.activation.ActivationMonitor; +import java.rmi.activation.ActivationSystem; +import java.rmi.activation.UnknownGroupException; +import java.rmi.activation.UnknownObjectException; + +import junit.framework.TestCase; + +public class ActivationGroupIDTest extends TestCase { + + class MyActivationSystem implements ActivationSystem{ + + public MyActivationSystem() throws ActivationException{ + + } + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#activeGroup(java.rmi.activation.ActivationGroupID, java.rmi.activation.ActivationInstantiator, long) + */ + public ActivationMonitor activeGroup(ActivationGroupID gID, + ActivationInstantiator aInst, long incarnation) + throws UnknownGroupException, ActivationException, + RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#getActivationDesc(java.rmi.activation.ActivationID) + */ + public ActivationDesc getActivationDesc(ActivationID aID) + throws ActivationException, UnknownObjectException, + RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#getActivationGroupDesc(java.rmi.activation.ActivationGroupID) + */ + public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID gID) + throws ActivationException, UnknownGroupException, + RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#registerGroup(java.rmi.activation.ActivationGroupDesc) + */ + public ActivationGroupID registerGroup(ActivationGroupDesc gDesc) + throws ActivationException, RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#registerObject(java.rmi.activation.ActivationDesc) + */ + public ActivationID registerObject(ActivationDesc aDesc) + throws ActivationException, UnknownGroupException, + RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#setActivationDesc(java.rmi.activation.ActivationID, java.rmi.activation.ActivationDesc) + */ + public ActivationDesc setActivationDesc(ActivationID aID, + ActivationDesc aDesc) throws ActivationException, + UnknownObjectException, UnknownGroupException, RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#setActivationGroupDesc(java.rmi.activation.ActivationGroupID, java.rmi.activation.ActivationGroupDesc) + */ + public ActivationGroupDesc setActivationGroupDesc( + ActivationGroupID gID, ActivationGroupDesc gDesc) + throws ActivationException, UnknownGroupException, + RemoteException { + return null; + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#shutdown() + */ + public void shutdown() throws RemoteException { + + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#unregisterGroup(java.rmi.activation.ActivationGroupID) + */ + public void unregisterGroup(ActivationGroupID gID) + throws ActivationException, UnknownGroupException, + RemoteException { + + } + + /* (non-Javadoc) + * @see java.rmi.activation.ActivationSystem#unregisterObject(java.rmi.activation.ActivationID) + */ + public void unregisterObject(ActivationID aID) + throws ActivationException, UnknownObjectException, + RemoteException { + + } + + } + + public void testEquals(){ + try { + ActivationSystem as = new MyActivationSystem(); + + ActivationGroupID agid = new ActivationGroupID(as); + ActivationGroupID agid2 = agid; + ActivationGroupID agid3 = new ActivationGroupID(as); + + assertSame(agid2, agid); + assertFalse(agid.equals(agid3)); + } catch (ActivationException e) { + e.printStackTrace(); + fail(); + } + } + + public void testGetSystem(){ + + try { + ActivationSystem as = new MyActivationSystem(); + ActivationGroupID agid = new ActivationGroupID(as); + + assertSame(as, agid.getSystem()); + } catch (ActivationException e) { + fail(); + } + } + + public void testHashcode(){ + try { + ActivationSystem as = new MyActivationSystem(); + + ActivationGroupID agid = new ActivationGroupID(as); + ActivationGroupID agid3 = new ActivationGroupID(as); + + assertTrue(agid.hashCode() != agid3.hashCode()); + } catch (ActivationException e) { + fail(); + } + } + + public void testToString(){ + try { + ActivationSystem as = new MyActivationSystem(); + + ActivationGroupID agid = new ActivationGroupID(as); + ActivationGroupID agid3 = new ActivationGroupID(as); + + assertTrue(!agid.toString().equals(agid3.toString())); + } catch (ActivationException e) { + fail(); + } + } + + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/VMIDTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/VMIDTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/VMIDTest.java (revision 0) @@ -0,0 +1,94 @@ +/* + * 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.harmony.rmi.tests.java.rmi.dgc; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.InetAddress; +import java.rmi.dgc.VMID; + +import junit.framework.TestCase; + +public class VMIDTest extends TestCase { + + public void testEquals() { + VMID vmid = new VMID(); + VMID vmid2 = new VMID(); + + assertTrue(vmid.equals(vmid)); + assertFalse(vmid.equals(vmid2)); + } + + public void testHashCode(){ + VMID vmid = new VMID(); + VMID vmid2 = new VMID(); + + assertTrue(vmid.hashCode() != vmid2.hashCode()); + assertTrue(vmid.hashCode() == vmid.hashCode()); + } + + public void testToString(){ + VMID vmid = new VMID(); + VMID vmid2 = new VMID(); + assertEquals(vmid.toString(), vmid.toString()); + + assertTrue(!vmid.toString().equals(vmid2.toString())); + } + + public void testIsUnique(){ + VMID vmid = new VMID(); + boolean unique = true; + try { + InetAddress.getLocalHost(); + } catch (Exception ex) { + unique = false; + } + + assertTrue(unique == vmid.isUnique()); + } + + public void testReadWriteObject(){ + try { + VMID vmid = new VMID(); + + File tmpFile = File.createTempFile("VMIDTest", "tmp"); + ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(tmpFile)); + output.writeObject(vmid); + output.flush(); + output.close(); + + VMID vmid2 = null; + ObjectInputStream input = + new ObjectInputStream(new FileInputStream(tmpFile)); + vmid2 = (VMID) input.readObject(); + input.close(); + tmpFile.delete(); + + assertTrue(vmid.equals(vmid2)); + } catch (IOException e) { + fail(e.getMessage()); + } catch (ClassNotFoundException e) { + fail(e.getMessage()); + } + } + + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/LeaseTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/LeaseTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/java/rmi/dgc/LeaseTest.java (revision 0) @@ -0,0 +1,36 @@ +/* + * 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.harmony.rmi.tests.java.rmi.dgc; + +import java.rmi.dgc.Lease; +import java.rmi.dgc.VMID; + +import junit.framework.TestCase; + +public class LeaseTest extends TestCase { + + public void testGetValueAndGetVMID() { + VMID vmid = new VMID(); + long duration = (long) Math.random() * Long.MAX_VALUE; + + Lease lease = new Lease(vmid, duration); + + assertEquals(duration, lease.getValue()); + assertEquals(vmid, lease.getVMID()); + } + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/InvalidActivityExceptionTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/InvalidActivityExceptionTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/InvalidActivityExceptionTest.java (revision 0) @@ -0,0 +1,49 @@ +/* + * 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.harmony.rmi.tests.javax.activity; + +import javax.activity.InvalidActivityException; + +import junit.framework.TestCase; + +public class InvalidActivityExceptionTest extends TestCase { + + public void test_Constructor(){ + InvalidActivityException are = new InvalidActivityException(); + assertNull(null, are.getMessage()); + } + + public void test_Constructor_String(){ + InvalidActivityException are = new InvalidActivityException("Hello"); + assertEquals("Hello", are.getMessage()); + } + + public void test_Constructor_String_Throwable() { + Throwable cause = new Throwable(); + InvalidActivityException ace = new InvalidActivityException( + "Hello", cause); + + assertSame(cause, ace.getCause()); + } + + public void test_Constructor_Throwable() { + Throwable cause = new Throwable(); + InvalidActivityException ace = new InvalidActivityException(cause); + + assertSame(cause, ace.getCause()); + } +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityCompletedExceptionTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityCompletedExceptionTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityCompletedExceptionTest.java (revision 0) @@ -0,0 +1,50 @@ +/* + * 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.harmony.rmi.tests.javax.activity; + +import javax.activity.ActivityCompletedException; + +import junit.framework.TestCase; + +public class ActivityCompletedExceptionTest extends TestCase { + + public void test_Constructor() { + ActivityCompletedException ace = new ActivityCompletedException(); + assertNull(ace.getMessage()); + } + + public void test_Constructor_String() { + ActivityCompletedException ace = new ActivityCompletedException("Hello"); + assertEquals("Hello", ace.getMessage()); + } + + public void test_Constructor_String_Throwable() { + Throwable cause = new Throwable(); + ActivityCompletedException ace = new ActivityCompletedException( + "Hello", cause); + + assertSame(cause, ace.getCause()); + } + + public void test_Constructor_Throwable() { + Throwable cause = new Throwable(); + ActivityCompletedException ace = new ActivityCompletedException(cause); + + assertSame(cause, ace.getCause()); + } + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityRequiredExceptionTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityRequiredExceptionTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/tests/javax/activity/ActivityRequiredExceptionTest.java (revision 0) @@ -0,0 +1,50 @@ +/* + * 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.harmony.rmi.tests.javax.activity; + +import javax.activity.ActivityCompletedException; +import javax.activity.ActivityRequiredException; + +import junit.framework.TestCase; + +public class ActivityRequiredExceptionTest extends TestCase { + + public void test_Constructor(){ + ActivityRequiredException are = new ActivityRequiredException(); + assertNull(null, are.getMessage()); + } + + public void test_Constructor_String(){ + ActivityRequiredException are = new ActivityRequiredException("Hello"); + assertEquals("Hello", are.getMessage()); + } + + public void test_Constructor_String_Throwable() { + Throwable cause = new Throwable(); + ActivityRequiredException ace = new ActivityRequiredException( + "Hello", cause); + + assertSame(cause, ace.getCause()); + } + + public void test_Constructor_Throwable() { + Throwable cause = new Throwable(); + ActivityRequiredException ace = new ActivityRequiredException(cause); + + assertSame(cause, ace.getCause()); + } +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/OperationTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/OperationTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/OperationTest.java (revision 0) @@ -0,0 +1,33 @@ +/* + * 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.harmony.rmi.server; + +import java.rmi.server.Operation; + +import junit.framework.TestCase; + +public class OperationTest extends TestCase { + + public void testOperations() { + String methoddesc = "Class_forName_[String;"; + Operation op = new Operation(methoddesc); + + assertEquals(op.getOperation(), methoddesc); + assertEquals(op.toString(), methoddesc); + } + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/ServerNotActiveExceptionTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/ServerNotActiveExceptionTest.java (revision 998619) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/ServerNotActiveExceptionTest.java (working copy) @@ -66,6 +66,12 @@ ServerNotActiveException e = new ServerNotActiveException(errorMessage); assertEquals(errorMessage, e.getMessage()); } + + + public void test_Constructor(){ + ServerNotActiveException e = new ServerNotActiveException(); + assertNull(e.getMessage()); + } // comparator for ServerNotActiveException objects private static final SerializableAssert comparator = new SerializableAssert() { Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteObjectTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteObjectTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteObjectTest.java (revision 0) @@ -0,0 +1,146 @@ +/* + * 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.harmony.rmi.server; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.server.Operation; +import java.rmi.server.RemoteCall; +import java.rmi.server.RemoteObject; +import java.rmi.server.RemoteRef; + +import junit.framework.TestCase; + +public class RemoteObjectTest extends TestCase { + + class MyRef implements RemoteRef { + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#done(java.rmi.server.RemoteCall) + */ + public void done(RemoteCall call) throws RemoteException { + + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput) + */ + public String getRefClass(ObjectOutput out) { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#invoke(java.rmi.Remote, + * java.lang.reflect.Method, java.lang.Object[], long) + */ + public Object invoke(Remote obj, Method m, Object[] params, long h) + throws Exception { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#invoke(java.rmi.server.RemoteCall) + */ + public void invoke(RemoteCall call) throws Exception { + + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#newCall(java.rmi.server.RemoteObject, + * java.rmi.server.Operation[], int, long) + */ + public RemoteCall newCall(RemoteObject obj, Operation[] op, int a1, + long a2) throws RemoteException { + return null; + } + + /* + * (non-Javadoc) + * + * @see + * java.rmi.server.RemoteRef#remoteEquals(java.rmi.server.RemoteRef) + */ + public boolean remoteEquals(RemoteRef ref) { + return false; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#remoteHashCode() + */ + public int remoteHashCode() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#remoteToString() + */ + public String remoteToString() { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + public void readExternal(ObjectInput in) throws IOException, + ClassNotFoundException { + + } + + /* + * (non-Javadoc) + * + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + public void writeExternal(ObjectOutput out) throws IOException { + + } + + } + + class MyRemoteObject extends RemoteObject { + public MyRemoteObject(RemoteRef ref) { + this.ref = ref; + } + } + + public void testGetRef() { + MyRef ref = new MyRef(); + MyRemoteObject obj = new MyRemoteObject(ref); + + assertSame(ref, obj.getRef()); + } +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteServerTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteServerTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteServerTest.java (revision 0) @@ -0,0 +1,55 @@ +/* + * 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.harmony.rmi.server; + +import java.rmi.server.RemoteServer; +import java.rmi.server.ServerNotActiveException; +import java.security.Permission; + +import junit.framework.TestCase; + +public class RemoteServerTest extends TestCase { + + public void testLog() { + SecurityManager sm = new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + return; + } + }; + SecurityManager previous = System.getSecurityManager(); + System.setSecurityManager(sm); + try { + RemoteServer.setLog(null); + assertNull(RemoteServer.getLog()); + } catch (Exception e) { + fail(); + } finally { + System.setSecurityManager(previous); + } + } + + public void testGetClientHost() { + try { + RemoteServer.getClientHost(); + fail(); + } catch (ServerNotActiveException e) { + + } + } + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java (revision 998619) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java (working copy) @@ -19,10 +19,13 @@ package org.apache.harmony.rmi.server; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.rmi.server.RMIClassLoader; +import java.rmi.server.RMIClassLoaderSpi; import java.security.Permission; + import junit.framework.TestCase; public class RMIClassLoaderTest extends TestCase { @@ -52,8 +55,8 @@ * to be sure this path will be the first after sorting */ "/_fake.jar" }; - Class c = RMIClassLoader.loadClass("file://" + paths[0] + " file://" + paths[1], - "TestClass", null); + Class c = RMIClassLoader.loadClass("file://" + paths[0] + + " file://" + paths[1], "TestClass", null); ClassLoader cl = c.getClassLoader(); if (cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); @@ -63,8 +66,8 @@ String failStr = ""; for (int i = 0; i < urls.length; ++i) { if (!urls[i].getPath().equals(paths[i])) { - failStr += "\nURL[" + i + "].getPath() = " + urls[i].getPath() - + ", expected: " + paths[i]; + failStr += "\nURL[" + i + "].getPath() = " + + urls[i].getPath() + ", expected: " + paths[i]; } } if (!failStr.equals("")) { @@ -80,59 +83,271 @@ } /** - * Test for java.rmi.server.RMIClassLoader.loadProxyClass(String, String[], ClassLoader) - * testing invalid url as a codebase. - */ + * Test for java.rmi.server.RMIClassLoader.loadProxyClass(String, String[], + * ClassLoader) testing invalid url as a codebase. + */ public void testLoadProxyClassInvalidCodebase() throws Exception { - //Regression for HARMONY-1133 + // Regression for HARMONY-1133 SecurityManager previous = System.getSecurityManager(); System.setSecurityManager(null); - + try { RMIClassLoader.loadProxyClass("zzz", new String[] {}, null); fail("MalformedURLException expected"); - } catch (MalformedURLException e) { - //expected + } catch (MalformedURLException e) { + // expected } finally { - System.setSecurityManager(previous); + System.setSecurityManager(previous); } } /** - * Test for java.rmi.server.RMIClassLoader.loadClass(String, String) - * testing invalid url as a codebase. + * Test for java.rmi.server.RMIClassLoader.loadClass(String, String) testing + * invalid url as a codebase. */ public void testLoadClassInvalidCodebase() throws Exception { - //Regression for HARMONY-1133 + // Regression for HARMONY-1133 SecurityManager previous = System.getSecurityManager(); System.setSecurityManager(null); - - try { + + try { RMIClassLoader.loadClass("zzz", "a123"); fail("MalformedURLException expected"); - } catch (MalformedURLException e) { - //expected + } catch (MalformedURLException e) { + // expected } finally { - System.setSecurityManager(previous); - } + System.setSecurityManager(previous); + } } /** - * Test for java.rmi.server.RMIClassLoader.getClassLoader(String) - * testing invalid url as a codebase. + * Test for java.rmi.server.RMIClassLoader.getClassLoader(String) testing + * invalid url as a codebase. */ public void testGetClassLoaderInvalidCodebase() throws Exception { - //Regression for HARMONY-1134 + // Regression for HARMONY-1134 SecurityManager previous = System.getSecurityManager(); System.setSecurityManager(null); - try { + try { RMIClassLoader.getClassLoader("zzz"); fail("MalformedURLException expected"); - } catch (MalformedURLException e) { - //expected + } catch (MalformedURLException e) { + // expected } finally { - System.setSecurityManager(previous); - } + System.setSecurityManager(previous); + } } + + /** + * Modify the above method to test loadClass, loadClass(String, String) for + * coverage. + */ + public void testLoadClassCodebaseOrder2() throws Exception { + SecurityManager previous = System.getSecurityManager(); + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + }); + try { + URL testJarURL = getClass().getResource("testClass.jar"); + String[] paths = new String[] { testJarURL.getPath(), + /* + * to be sure this path will be the first after sorting + */ + "/_fake.jar" }; + Class c = RMIClassLoader.loadClass("file://" + paths[0] + + " file://" + paths[1], "TestClass"); + ClassLoader cl = c.getClassLoader(); + if (cl instanceof URLClassLoader) { + URL[] urls = ((URLClassLoader) cl).getURLs(); + if (urls.length != 2) { + fail("Unexpected number of URLs: " + urls.length); + } + String failStr = ""; + for (int i = 0; i < urls.length; ++i) { + if (!urls[i].getPath().equals(paths[i])) { + failStr += "\nURL[" + i + "].getPath() = " + + urls[i].getPath() + ", expected: " + paths[i]; + } + } + if (!failStr.equals("")) { + fail(failStr); + } + } else { + fail("Class is loaded by non-URLClassLoader"); + } + } finally { + // reset the security manager back to null state + System.setSecurityManager(previous); + } + } + + /** + * Modify the above method to test loadClass, loadClass(String, String) for + * coverage. + */ + public void testLoadClassCodebaseOrder3() throws Exception { + SecurityManager previous = System.getSecurityManager(); + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + }); + try { + URL testJarURL = getClass().getResource("testClass.jar"); + String[] paths = new String[] { testJarURL.getPath(), + /* + * to be sure this path will be the first after sorting + */ + "/_fake.jar" }; + + Class c = RMIClassLoader.loadClass(new URI("file://" + paths[0]) + .toURL(), "TestClass"); + + assertNotNull(c); + + } catch (Exception e) { + fail("class should be loaded"); + } finally { + // reset the security manager back to null state + System.setSecurityManager(previous); + } + } + + /** + * Modify the above method to test testGetSecurityContext for coverage. + */ + public void testGetSecurityContext() throws Exception { + SecurityManager previous = System.getSecurityManager(); + SecurityManager sm = new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + + }; + System.setSecurityManager(sm); + try { + URL testJarURL = getClass().getResource("testClass.jar"); + String[] paths = new String[] { testJarURL.getPath(), + /* + * to be sure this path will be the first after sorting + */ + "/_fake.jar" }; + + Class c = RMIClassLoader.loadClass(new URI("file://" + paths[0]) + .toURL(), "TestClass"); + + assertNotNull(c); + + Object sc = RMIClassLoader.getSecurityContext(c.getClassLoader()); + if (true) { + return; + } + + // This is the ri behavior, spec for what to return is not found + assertEquals(((URL) sc).toString(), testJarURL.toString()); + } catch (Exception e) { + // e.printStackTrace(); + fail("class should be loaded"); + } finally { + // reset the security manager back to null state + System.setSecurityManager(previous); + } + } + + public void testGetDefaultProvideInstance() { + assertTrue(RMIClassLoader.getDefaultProviderInstance() instanceof RMIClassLoaderSpi); + } + + /** + * Modify the above method to test loadClass, loadClass(String, String) for + * coverage. + */ + public void testLoadClassCodebaseOrder4() throws Exception { + SecurityManager previous = System.getSecurityManager(); + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + }); + try { + URL testJarURL = getClass().getResource("testClass.jar"); + String[] paths = new String[] { testJarURL.getPath(), + /* + * to be sure this path will be the first after sorting + */ + "/_fake.jar" }; + + ClassLoader cl = RMIClassLoader.getClassLoader(new URI("file://" + + paths[0]).toURL().toString()); + Class c = cl.loadClass("TestClass"); + + assertNotNull(c); + + } catch (Exception e) { + fail("class should be loaded"); + } finally { + // reset the security manager back to null state + System.setSecurityManager(previous); + } + } + + /** + * Modify the above method to test loadClass, loadClass(String, String) for + * coverage. + */ + public void testLoadClassCodebaseOrder5() throws Exception { + SecurityManager previous = System.getSecurityManager(); + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + }); + try { + Class c = RMIClassLoader.loadClass("TestClass"); + assertNotNull(c); + } catch (ClassNotFoundException e) { + + } finally { + // reset the security manager back to null state + System.setSecurityManager(previous); + } + } } Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMISocketFactoryTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMISocketFactoryTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RMISocketFactoryTest.java (revision 0) @@ -0,0 +1,90 @@ +/* + * 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.harmony.rmi.server; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.rmi.server.RMIFailureHandler; +import java.rmi.server.RMISocketFactory; +import java.security.Permission; + +import junit.framework.TestCase; + +public class RMISocketFactoryTest extends TestCase { + + public void testGetSetFailureHandler() { + RMIFailureHandler fh = new RMIFailureHandler() { + public boolean failure(Exception ex) { + return false; + } + }; + + RMISocketFactory.setFailureHandler(fh); + assertSame(fh, RMISocketFactory.getFailureHandler()); + } + + public void testSetSocketFactory() { + SecurityManager previous = System.getSecurityManager(); + SecurityManager sm = new SecurityManager() { + @Override + public void checkPermission(Permission perm) { + /* + * Override checkPermission to allow everything. Specifically, + * we want to allow the SecurityManager to be set to null at the + * end of the test and we want to allow the 'testClass.jar' file + * to be allowed to load. + */ + return; + } + + @Override + public void checkSetFactory() { + throw new SecurityException(); + } + + }; + System.setSecurityManager(sm); + + RMISocketFactory sf = new RMISocketFactory() { + + @Override + public ServerSocket createServerSocket(int port) throws IOException { + return null; + } + + @Override + public Socket createSocket(String host, int port) + throws IOException { + return null; + } + }; + + try { + RMISocketFactory.setSocketFactory(sf); + fail(); + } catch (SecurityException e) { + return; + } catch (IOException e) { + fail(); + } finally { + System.setSecurityManager(previous); + } + + } + +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteStubTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteStubTest.java (revision 0) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/RemoteStubTest.java (revision 0) @@ -0,0 +1,162 @@ +/* + * 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.harmony.rmi.server; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.server.Operation; +import java.rmi.server.RemoteCall; +import java.rmi.server.RemoteObject; +import java.rmi.server.RemoteRef; +import java.rmi.server.RemoteStub; + +import junit.framework.TestCase; + +public class RemoteStubTest extends TestCase { + + class MyRemoteRef implements RemoteRef { + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#done(java.rmi.server.RemoteCall) + */ + public void done(RemoteCall call) throws RemoteException { + + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput) + */ + public String getRefClass(ObjectOutput out) { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#invoke(java.rmi.Remote, + * java.lang.reflect.Method, java.lang.Object[], long) + */ + public Object invoke(Remote obj, Method m, Object[] params, long h) + throws Exception { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#invoke(java.rmi.server.RemoteCall) + */ + public void invoke(RemoteCall call) throws Exception { + + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#newCall(java.rmi.server.RemoteObject, + * java.rmi.server.Operation[], int, long) + */ + public RemoteCall newCall(RemoteObject obj, Operation[] op, int a1, + long a2) throws RemoteException { + return null; + } + + /* + * (non-Javadoc) + * + * @see + * java.rmi.server.RemoteRef#remoteEquals(java.rmi.server.RemoteRef) + */ + public boolean remoteEquals(RemoteRef ref) { + return false; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#remoteHashCode() + */ + public int remoteHashCode() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see java.rmi.server.RemoteRef#remoteToString() + */ + public String remoteToString() { + return null; + } + + /* + * (non-Javadoc) + * + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + public void readExternal(ObjectInput in) throws IOException, + ClassNotFoundException { + + } + + /* + * (non-Javadoc) + * + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + public void writeExternal(ObjectOutput out) throws IOException { + + } + + } + + public void testSetRef() { + MyRemoteStub stub = new MyRemoteStub(); + RemoteRef ref = new MyRemoteRef(); + + MyRemoteStub.setRef(stub, ref); + + assertEquals(ref, stub.getRef()); + } + +} + +class MyRemoteStub extends RemoteStub { + public RemoteRef getRef() { + return ref; + } + + public MyRemoteStub() { + super(); + } + + public MyRemoteStub(RemoteRef ref) { + super(ref); + } + + public static void setRef(RemoteStub stub, RemoteRef ref) { + RemoteStub.setRef(stub, ref); + } +} Index: classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java =================================================================== --- classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java (revision 998619) +++ classlib/modules/rmi/src/test/api/java/org/apache/harmony/rmi/server/LogStreamTest.java (working copy) @@ -18,8 +18,10 @@ package org.apache.harmony.rmi.server; import java.io.ByteArrayOutputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.rmi.server.LogStream; + import junit.framework.TestCase; public class LogStreamTest extends TestCase { @@ -27,13 +29,13 @@ * Test for java.rmi.server.LogStream.write(int b) */ public void testWriteI() throws Exception { - //regression test for HARMONY-1271 - LogStream.log("tst").write((int)'\n'); + // regression test for HARMONY-1271 + LogStream.log("tst").write((int) '\n'); - //regression test for HARMONY-994 + // regression test for HARMONY-994 LogStream.log("tst").write(0); } - + public void testSetOutputStreamBad() throws Exception { // Regression test HARMONY-1198 try { @@ -46,41 +48,54 @@ } /** - * Test for java.rmi.server.LogStream.write(byte[], int, int) - * testing invalid offsets/lengths. + * Test for java.rmi.server.LogStream.write(byte[], int, int) testing + * invalid offsets/lengths. */ public void testWriteArrInvalidOffLen() throws Exception { // Regression test for HARMONY-1691 // list of invalid offsets/lengths pairs - int[][] invalidPairs = new int[][] { - { -2, 1 }, - { 0, -6 }, - { 6, 1 }, - { 0, 6 } }; + int[][] invalidPairs = new int[][] { { -2, 1 }, { 0, -6 }, { 6, 1 }, + { 0, 6 } }; // store original default stream for LogStream PrintStream prevOut = LogStream.getDefaultStream(); try { // set empty default stream to not print garbage to System.out/err - LogStream.setDefaultStream( - new PrintStream(new ByteArrayOutputStream())); + LogStream.setDefaultStream(new PrintStream( + new ByteArrayOutputStream())); LogStream ls = LogStream.log("test"); for (int i = 0; i < invalidPairs.length; ++i) { try { - ls.write(new byte[] { 1, 1 }, - invalidPairs[i][0], invalidPairs[i][1]); + ls.write(new byte[] { 1, 1 }, invalidPairs[i][0], + invalidPairs[i][1]); fail("IndexOutOfBoundsException " + "is not thrown when off = " + invalidPairs[i][0] + ", len = " + invalidPairs[i][1]); } catch (IndexOutOfBoundsException e) { - //expected + // expected } } } finally { // restore original stream LogStream.setDefaultStream(prevOut); } + } + + public void testParseLevel() { + assertEquals(LogStream.parseLevel("BRIEF"), LogStream.BRIEF); + assertEquals(LogStream.parseLevel("SILENT"), LogStream.SILENT); + assertEquals(LogStream.parseLevel("VERBOSE"), LogStream.VERBOSE); + } + + public void testGetOutputStream() { + LogStream log = LogStream.log("abc"); + OutputStream output = log.getOutputStream(); + PrintStream defaultPrintStream = LogStream.getDefaultStream(); + + assertEquals(output.toString(), defaultPrintStream.toString()); + } + }