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;
}
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());
}
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()));
}
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());
}
Aggregations