Skip to content

Commit

Permalink
Merge pull request #223 from joe-chacko/port-poa-test
Browse files Browse the repository at this point in the history
Port poa test
  • Loading branch information
habiblawal1 authored Aug 2, 2023
2 parents 65c7bbe + 277b36c commit 38fa69a
Show file tree
Hide file tree
Showing 21 changed files with 893 additions and 2,406 deletions.
4 changes: 2 additions & 2 deletions RMI_Demo/finish/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repositories {

dependencies {
testImplementation 'org.apache.yoko:yoko-testify:1.5.0.9cce293956'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testRuntimeOnly 'org.junit.platform:junit-platform-runner:1.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
}

test {
Expand Down
4 changes: 2 additions & 2 deletions RMI_Demo/start/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ repositories {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testRuntimeOnly 'org.junit.platform:junit-platform-runner:1.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
}

test {
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ subprojects { sp ->
testLib 'org.mockito:mockito-core:2.22.0'
testLib 'org.mockito:mockito-junit-jupiter:2.22.0'
testLib "org.hamcrest:hamcrest:2.1"
testLib "org.junit.jupiter:junit-jupiter:5.8.2"
testLib "org.junit.jupiter:junit-jupiter:5.9.0"
testLib "org.junit.platform:junit-platform-runner:1.8.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.8.2"
testLib "org.junit-pioneer:junit-pioneer:1.9.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.0"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.9.0"
}

if (JavaVersion.current() < JavaVersion.VERSION_11) {
Expand Down
2 changes: 1 addition & 1 deletion testify-iiop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies {
implementation 'junit:junit:4.12'
implementation "org.hamcrest:hamcrest:2.1"
implementation "org.junit.jupiter:junit-jupiter:5.8.2"
implementation "org.junit.jupiter:junit-jupiter:5.9.0"
implementation project(':yoko-spec-corba')
implementation project(':yoko-rmi-spec')
implementation project(":yoko-core")
Expand Down
2 changes: 1 addition & 1 deletion testify/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
implementation "org.hamcrest:hamcrest:2.1"
implementation "org.junit.jupiter:junit-jupiter:5.8.2"
implementation "org.junit.jupiter:junit-jupiter:5.9.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2023 IBM Corporation and others.
*
* Licensed 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.apache.yoko.orb.PortableServer;

import org.omg.CORBA.Policy;
import org.omg.PortableServer.IdAssignmentPolicyValue;
import org.omg.PortableServer.IdUniquenessPolicyValue;
import org.omg.PortableServer.ImplicitActivationPolicyValue;
import org.omg.PortableServer.LifespanPolicyValue;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
import org.omg.PortableServer.POAPackage.InvalidPolicy;
import org.omg.PortableServer.RequestProcessingPolicyValue;
import org.omg.PortableServer.ServantRetentionPolicyValue;

import java.util.function.Function;
import java.util.stream.Stream;

public enum PolicyValue {
UNIQUE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.UNIQUE_ID)),
MULTIPLE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.MULTIPLE_ID)),
RETAIN(poa -> poa.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN)),
NON_RETAIN(poa -> poa.create_servant_retention_policy(ServantRetentionPolicyValue.NON_RETAIN)),
NO_IMPLICIT_ACTIVATION(poa -> poa.create_implicit_activation_policy(ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION)),
IMPLICIT_ACTIVATION(poa -> poa.create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)),
USER_ID(poa -> poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID)),
SYSTEM_ID(poa -> poa.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID)),
PERSISTENT(poa -> poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)),
USE_DEFAULT_SERVANT(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)),
USE_SERVANT_MANAGER(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER)),
USE_ACTIVE_OBJECT_MAP_ONLY(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY));

final Function<POA, Policy> factory;

PolicyValue(Function<POA, Policy> factory) {
this.factory = factory;
}

static POA create_POA(String id, POA parentPoa, POAManager poaMgr, PolicyValue...policies) throws InvalidPolicy, AdapterAlreadyExists {
Policy[] policyList = Stream.of(policies)
.map(policy -> policy.factory.apply(parentPoa))
.toArray(Policy[]::new);
return parentPoa.create_POA(id, poaMgr, policyList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class TestPoaActivate {
private static Test_impl servant2;

@BeforeAll
private static void setup(ORB orb, POA rootPoa) throws Exception {
static void setup(ORB orb, POA rootPoa) throws Exception {
rootPoa.the_POAManager().activate();
servant1 = new Test_impl(orb, "obj1", false);
servant2 = new Test_impl(orb, "obj2", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2023 IBM Corporation and others.
*
* Licensed 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.apache.yoko.orb.PortableServer;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junitpioneer.jupiter.cartesian.CartesianTest;
import org.junitpioneer.jupiter.cartesian.CartesianTest.Enum;
import org.omg.CORBA.LocalObject;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Request;
import org.omg.PortableServer.ForwardRequest;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.Servant;
import org.omg.PortableServer.ServantActivator;
import org.omg.PortableServer.ServantLocator;
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
import test.poa.TestDSIRef_impl;
import test.poa.TestHelper;
import test.poa.Test_impl;
import testify.iiop.annotation.ConfigureOrb;

import static org.apache.yoko.orb.PortableServer.PolicyValue.MULTIPLE_ID;
import static org.apache.yoko.orb.PortableServer.PolicyValue.NON_RETAIN;
import static org.apache.yoko.orb.PortableServer.PolicyValue.NO_IMPLICIT_ACTIVATION;
import static org.apache.yoko.orb.PortableServer.PolicyValue.PERSISTENT;
import static org.apache.yoko.orb.PortableServer.PolicyValue.RETAIN;
import static org.apache.yoko.orb.PortableServer.PolicyValue.UNIQUE_ID;
import static org.apache.yoko.orb.PortableServer.PolicyValue.USER_ID;
import static org.apache.yoko.orb.PortableServer.PolicyValue.USE_DEFAULT_SERVANT;
import static org.apache.yoko.orb.PortableServer.PolicyValue.USE_SERVANT_MANAGER;
import static org.apache.yoko.orb.PortableServer.PolicyValue.create_POA;

@ConfigureOrb
public class TestPoaCollocated {
enum ConfigurePoa {
STATIC_DEFAULT_SERVANT (PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT),
DYNAMIC_DEFAULT_SERVANT(PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT),
SERVANT_LOCATOR (PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER),
SERVANT_ACTIVATOR (PERSISTENT, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER);
final PolicyValue[] policyValues;
ConfigurePoa(PolicyValue... policyValues) { this.policyValues = policyValues; }

void configurePoa(TestPoaCollocated t) throws Exception {
t.poa = create_POA(name(), t.rootPoa, t.rootPoaManager, policyValues);
switch (this) {
case STATIC_DEFAULT_SERVANT: t.poa.set_servant(new Test_impl(t.orb, "defaultStaticServant", false)); return;
case DYNAMIC_DEFAULT_SERVANT: t.poa.set_servant(new TestDSIRef_impl(t.orb, "defaultDSIServant", false)); return;
case SERVANT_LOCATOR: t.poa.set_servant_manager(t.new TestLocator()); return;
case SERVANT_ACTIVATOR: t.poa.set_servant_manager(t.new TestActivator()); return;
}
}
}
enum ChooseTarget { STATIC_SERVANT, DYNAMIC_SERVANT }
enum InvokeMethod {
STATIC_INVOKE {
void invoke(POA poa, String id) {
TestHelper.narrow(poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0")).aMethod();
}
},
DYNAMIC_INVOKE {
void invoke(POA poa, String id) throws Exception {
org.omg.CORBA.Object object = poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0");
Request request = object._request("aMethod");
request.invoke(); // dynamic invocation
if (null != request.env().exception()) throw request.env().exception();
}
};
abstract void invoke(POA poa, String id) throws Exception ;
}

ORB orb;
POA rootPoa;
POAManager rootPoaManager;
POA poa;

@BeforeEach
void setup(ORB orb, POA rootPoa) {
this.orb = orb;
this.rootPoa = rootPoa;
this.rootPoaManager = rootPoa.the_POAManager();
// this.poa is configured during each test
}

@AfterEach
void destroyPoa() { poa.destroy(true, true); }

@CartesianTest // runs every combination of the three enums
void test(@Enum ConfigurePoa poaConfig, @Enum ChooseTarget target, @Enum InvokeMethod invoker) throws Exception {
poaConfig.configurePoa(this);
invoker.invoke(this.poa, target.name());
}

final class TestActivator extends LocalObject implements ServantActivator {
public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest {
switch (ChooseTarget.valueOf(new String(oid))) {
case STATIC_SERVANT: return new Test_impl(orb, "locator_SSI", false);
case DYNAMIC_SERVANT: return new TestDSIRef_impl(orb, "locator_DSI", false);
default: return null; // fail
}
}

public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) {}
}

final class TestLocator extends LocalObject implements ServantLocator {
private final Test_impl test = new Test_impl(orb, "locator_SSI", false);
private final TestDSIRef_impl testDSI = new TestDSIRef_impl(orb, "locator_DSI", false);

public Servant preinvoke(byte[] oid, POA poa, String operation, CookieHolder the_cookie) {
switch (ChooseTarget.valueOf(new String(oid))) {
case STATIC_SERVANT: return test;
case DYNAMIC_SERVANT: return testDSI;
default: return null;
}
}

public void postinvoke(byte[] oid, POA poa, String operation, Object the_cookie, Servant the_servant) {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2023 IBM Corporation and others.
*
* Licensed 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.apache.yoko.orb.PortableServer;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.omg.CORBA.Policy;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAManagerPackage.State;
import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
import org.omg.PortableServer.POAPackage.InvalidPolicy;
import testify.iiop.annotation.ConfigureOrb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN;

@ConfigureOrb
public class TestPoaCreate {
private static POAManager rootMgr;

@BeforeAll
static void setup(POA rootPoa) {
rootMgr = rootPoa.the_POAManager();
}

@Test
public void testCreatePOA(POA rootPoa) throws Exception {
// Create child POA
POA poa = rootPoa.create_POA("poa1", null, new Policy[]{});

// Test: POAManager should NOT be the same as the root's manager
POAManager mgr = poa.the_POAManager();
assertFalse(mgr._is_equivalent(rootMgr));

// Test: POAManager should be in HOLDING state
assertSame(mgr.get_state(), State.HOLDING);

// Test: Confirm name
String poaName = poa.the_name();
assertEquals("poa1", poaName);

// Test: Confirm parent
POA parent = poa.the_parent();
assertTrue(parent._is_equivalent(rootPoa));

assertThrows(AdapterAlreadyExists.class, () -> rootPoa.create_POA("poa1", null, new Policy[]{}));

//In order to use the NON_RETAIN policy, you must first have a servant manager
Policy[] invalidPolicies = { rootPoa.create_servant_retention_policy(NON_RETAIN) };
assertThrows(InvalidPolicy.class, () -> rootPoa.create_POA("invalid", null, invalidPolicies));

poa.destroy(true, true);
}

@Test
void testCreateChildOfChildPoa(POA rootPoa) throws Exception{
// Create another child of root POA
POA poa = rootPoa.create_POA("rootPoa", rootMgr, new Policy[]{});

// Test: POAManager should be the same as the root's manager
POAManager mgr = poa.the_POAManager();
assertTrue(mgr._is_equivalent(rootMgr));

// Create child of child POA
POA poa3 = poa.create_POA("child", rootMgr, new Policy[]{});

// Test: Confirm parent
POA parent = poa3.the_parent();
assertTrue(parent._is_equivalent(poa));

poa.destroy(true, true);
}
}
Loading

0 comments on commit 38fa69a

Please sign in to comment.