Search in sources :

Example 1 with TestClass2

use of org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2 in project activemq-artemis by apache.

the class ObjectInputStreamWithClassLoaderTest method testWhiteBlackListAgainstListMapObject.

@Test
public void testWhiteBlackListAgainstListMapObject() throws Exception {
    File serailizeFile = new File(temporaryFolder.getRoot(), "testclass.bin");
    Map<TestClass1, TestClass2> sourceObject = new HashMap<>();
    sourceObject.put(new TestClass1(), new TestClass2());
    ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(serailizeFile));
    try {
        outputStream.writeObject(sourceObject);
        outputStream.flush();
    } finally {
        outputStream.close();
    }
    String blackList = null;
    String whiteList = null;
    Object result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertNull(result);
    // now blacklist the key
    blackList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1";
    whiteList = null;
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertTrue(result instanceof ClassNotFoundException);
    // now blacklist the value
    blackList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2";
    whiteList = null;
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertTrue(result instanceof ClassNotFoundException);
    // now white list the key, should fail too because value is forbidden
    blackList = null;
    whiteList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1";
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertTrue(result instanceof ClassNotFoundException);
    // now white list the value, should fail too because the key is forbidden
    blackList = null;
    whiteList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2";
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertTrue(result instanceof ClassNotFoundException);
    // both key and value are in the whitelist, it should fail because HashMap not permitted
    blackList = null;
    whiteList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1," + "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2";
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertTrue(result instanceof ClassNotFoundException);
    // now add HashMap, test should pass.
    blackList = null;
    whiteList = "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1," + "org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2," + "java.util.HashMap";
    result = readSerializedObject(whiteList, blackList, serailizeFile);
    assertNull(result);
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) TestClass2(org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2) TestClass1(org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) Test(org.junit.Test)

Example 2 with TestClass2

use of org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2 in project aries by apache.

the class MBeanTest method test_simple_MBean_different_package.

@Test
public void test_simple_MBean_different_package() throws Exception {
    final String instanceName = "simple.test.instance.2";
    final String objectNameString = "domain:instance=" + instanceName;
    final ObjectName objectName = new ObjectName(objectNameString);
    final TestClass testInstance = new TestClass2(instanceName);
    final MBeanServer server = getStaticMBeanServer();
    // expect MBean to not be registered yet
    assertNotRegistered(server, objectName);
    // expect the MBean to be registered with the static server
    final ServiceRegistration reg = registerService(TestClassMBean.class.getName(), testInstance, objectNameString);
    assertRegistered(server, objectName);
    // expect MBean to return expected value
    TestCase.assertEquals(instanceName, server.getAttribute(objectName, "InstanceName"));
    // unregister MBean, expect to not be registered any more
    reg.unregister();
    assertNotRegistered(server, objectName);
}
Also used : TestClassMBean(org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean) TestClass(org.apache.aries.jmx.whiteboard.integration.helper.TestClass) TestClass2(org.apache.aries.jmx.whiteboard.integration.helper2.TestClass2) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 TestClass1 (org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass1)1 TestClass2 (org.apache.activemq.artemis.tests.unit.util.deserialization.pkg1.TestClass2)1 TestClass (org.apache.aries.jmx.whiteboard.integration.helper.TestClass)1 TestClassMBean (org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean)1 TestClass2 (org.apache.aries.jmx.whiteboard.integration.helper2.TestClass2)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1