Search in sources :

Example 1 with ByteArrayToObject

use of org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject in project mule by mulesoft.

the class ObjectByteArrayTransformersWithObjectsTestCase method getRoundTripTransformer.

@Override
public Transformer getRoundTripTransformer() throws Exception {
    ByteArrayToObject transfromer = new ByteArrayToObject();
    ((MuleContextWithRegistries) muleContext).getRegistry().registerObject(String.valueOf(transfromer.hashCode()), transfromer);
    return transfromer;
}
Also used : ByteArrayToObject(org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject)

Example 2 with ByteArrayToObject

use of org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject in project mule by mulesoft.

the class MuleEventTestCase method serialization.

@Test
public void serialization() throws Exception {
    Transformer transformer = createSerializableToByteArrayTransformer();
    transformer.setMuleContext(muleContext);
    Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(testEvent());
    assertNotNull(serialized);
    ByteArrayToObject trans = new ByteArrayToObject();
    trans.setMuleContext(muleContext);
    PrivilegedEvent deserialized = (PrivilegedEvent) trans.transform(serialized);
    // Assert that deserialized event is not null
    assertNotNull(deserialized);
    // Assert that deserialized event has session with same id
    assertNotNull(deserialized.getSession());
}
Also used : Serializable(java.io.Serializable) ByteArrayToObject(org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject) Transformer(org.mule.runtime.core.api.transformer.Transformer) AbstractTransformer(org.mule.runtime.core.api.transformer.AbstractTransformer) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Test(org.junit.Test)

Example 3 with ByteArrayToObject

use of org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject in project mule by mulesoft.

the class MuleEventTestCase method securityContextSerialization.

@Test
public void securityContextSerialization() throws Exception {
    Transformer transformer = createSerializableToByteArrayTransformer();
    transformer.setMuleContext(muleContext);
    CoreEvent event = CoreEvent.builder(testEvent()).securityContext(createTestAuthentication()).build();
    Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(event);
    assertNotNull(serialized);
    ByteArrayToObject trans = new ByteArrayToObject();
    trans.setMuleContext(muleContext);
    CoreEvent deserialized = (CoreEvent) trans.transform(serialized);
    assertThat(deserialized.getSecurityContext().getAuthentication().getPrincipal(), is(event.getSecurityContext().getAuthentication().getPrincipal()));
    assertThat(deserialized.getSecurityContext().getAuthentication().getProperties().get("key1"), is(event.getSecurityContext().getAuthentication().getProperties().get("key1")));
    assertThat(deserialized.getSecurityContext().getAuthentication().getCredentials(), is(event.getSecurityContext().getAuthentication().getCredentials()));
}
Also used : Serializable(java.io.Serializable) ByteArrayToObject(org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject) Transformer(org.mule.runtime.core.api.transformer.Transformer) AbstractTransformer(org.mule.runtime.core.api.transformer.AbstractTransformer) Test(org.junit.Test)

Example 4 with ByteArrayToObject

use of org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject in project mule by mulesoft.

the class MuleEventTestCase method testEventSerializationRestart.

@Test
public void testEventSerializationRestart() throws Exception {
    // Create and register artifacts
    CoreEvent event = createEventToSerialize();
    // Serialize
    Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(event);
    assertNotNull(serialized);
    // Simulate mule cold restart
    muleContext.dispose();
    muleContext = createMuleContext();
    muleContext.start();
    ByteArrayToObject trans = new ByteArrayToObject();
    trans.setMuleContext(muleContext);
    // Recreate and register artifacts (this would happen if using any kind of static config e.g. XML)
    createAndRegisterTransformersEndpointBuilderService();
    // Deserialize
    PrivilegedEvent deserialized = (PrivilegedEvent) trans.transform(serialized);
    // Assert that deserialized event is not null
    assertNotNull(deserialized);
    // Assert that deserialized event has session with same id
    assertNotNull(deserialized.getSession());
}
Also used : Serializable(java.io.Serializable) ByteArrayToObject(org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Test(org.junit.Test)

Aggregations

ByteArrayToObject (org.mule.runtime.core.privileged.transformer.simple.ByteArrayToObject)4 Serializable (java.io.Serializable)3 Test (org.junit.Test)3 AbstractTransformer (org.mule.runtime.core.api.transformer.AbstractTransformer)2 Transformer (org.mule.runtime.core.api.transformer.Transformer)2 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)2