@Test
 public void valid() {
   DefaultMuleSession session = new DefaultMuleSession();
   assertTrue(session.isValid());
   session.setValid(false);
   assertFalse(session.isValid());
   session.setValid(true);
   assertTrue(session.isValid());
 }
 protected void assertCreate(DefaultMuleSession session) {
   assertNotNull(session.getId());
   assertNull(session.getSecurityContext());
   assertNotNull(session.getPropertyNamesAsSet());
   assertTrue(session.getPropertyNamesAsSet().isEmpty());
   assertTrue(session.isValid());
 }
  @Test
  public void serialization() throws MuleException {
    Flow flow = new Flow("flow", Mockito.mock(MuleContext.class, RETURNS_DEEP_STUBS));
    DefaultMuleSession before = new DefaultMuleSession();
    before.setValid(false);
    before.setSecurityContext(createTestAuthentication());
    before.setProperty("foo", "bar");

    // Create mock muleContext
    MuleContext muleContext = Mockito.mock(MuleContext.class);
    MuleRegistry registry = Mockito.mock(MuleRegistry.class);
    Mockito.when(muleContext.getRegistry()).thenReturn(registry);
    Mockito.when(muleContext.getExecutionClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(registry.lookupFlowConstruct("flow")).thenReturn(flow);

    ((MuleContextAware) serializer).setMuleContext(muleContext);
    // Serialize and then deserialize
    DefaultMuleSession after = serializer.deserialize(serializer.serialize(before));

    // assertions
    assertEquals(before.getId(), after.getId());
    assertEquals(before.isValid(), after.isValid());
    assertEquals(before.getProperty("foo"), after.getProperty("foo"));
    assertEquals(
        before.getSecurityContext().getAuthentication().getPrincipal(),
        after.getSecurityContext().getAuthentication().getPrincipal());
    assertEquals(
        before.getSecurityContext().getAuthentication().getProperties().get("key1"),
        after.getSecurityContext().getAuthentication().getProperties().get("key1"));
    assertEquals(
        before.getSecurityContext().getAuthentication().getCredentials(),
        after.getSecurityContext().getAuthentication().getCredentials());
    // assertEquals(before.getSecurityContext().getAuthentication().getEvent().getId(),
    // after.getSecurityContext().getAuthentication().getEvent().getId());

    after.setProperty("new", "value");
    assertNull(before.getProperty("new"));
  }
 protected void assertCopy(DefaultMuleSession original, DefaultMuleSession copy) {
   assertSame(copy.getId(), original.getId());
   assertSame(copy.isValid(), original.isValid());
   assertSame(copy.getSecurityContext(), original.getSecurityContext());
 }