forked from apache/geronimo-yoko
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from joe-chacko/port-poa-test
Port poa test
- Loading branch information
Showing
21 changed files
with
893 additions
and
2,406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
61 changes: 61 additions & 0 deletions
61
yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.