예제 #1
0
 @Test
 public void testPropertiesCase() throws Exception {
   // Default scope
   MessagePropertiesContext mpc = new MessagePropertiesContext();
   mpc.setProperty("FOO", "BAR");
   mpc.setProperty("ABC", "abc");
   mpc.setProperty("DOO", "DAR", PropertyScope.INVOCATION);
   doTest(mpc);
 }
예제 #2
0
 @Test
 public void testInboundScopeIsImmutable() throws Exception {
   MessagePropertiesContext mpc = new MessagePropertiesContext();
   try {
     mpc.setProperty("key", "value", PropertyScope.INBOUND);
     fail("Inbound scope should be read-only");
   } catch (IllegalArgumentException iae) {
     // this exception was expectd
   }
 }
예제 #3
0
  @Test
  public void testSessionScope() throws Exception {
    MuleEvent e = getTestEvent("testing");
    e.getSession().setProperty("SESSION_PROP", "Value1");
    RequestContext.setEvent(e);

    MessagePropertiesContext mpc = new MessagePropertiesContext();

    assertEquals("Value1", mpc.getProperty("SESSION_PROP", PropertyScope.SESSION));
    // test case insensitivity
    assertEquals("Value1", mpc.getProperty("SESSION_prop", PropertyScope.SESSION));
    assertNull(mpc.getProperty("SESSION_X", PropertyScope.SESSION));
  }
예제 #4
0
  @Test
  public void testPropertiesCaseAfterSerialization() throws Exception {
    // Default scope
    MessagePropertiesContext mpc = new MessagePropertiesContext();
    mpc.setProperty("FOO", "BAR");
    mpc.setProperty("ABC", "abc");
    mpc.setProperty("DOO", "DAR", PropertyScope.INVOCATION);
    doTest(mpc);

    // Serialize and deserialize
    byte[] bytes = SerializationUtils.serialize(mpc);
    mpc = (MessagePropertiesContext) SerializationUtils.deserialize(bytes);
    doTest(mpc);
  }
예제 #5
0
  protected void doTest(MessagePropertiesContext mpc) {
    // Look in all scopes
    assertEquals("BAR", mpc.getProperty("foo"));
    assertEquals("DAR", mpc.getProperty("doo"));
    assertEquals("abc", mpc.getProperty("abc"));

    // Look in specific scope
    assertEquals("BAR", mpc.getProperty("foO", PropertyScope.OUTBOUND)); // default scope
    assertEquals("DAR", mpc.getProperty("doO", PropertyScope.INVOCATION));

    // Not found using other specific scopes
    assertNull(mpc.getProperty("doo", PropertyScope.INBOUND));
    assertNull(mpc.getProperty("doo", PropertyScope.OUTBOUND));
    assertNull(mpc.getProperty("doo", PropertyScope.SESSION));

    Set<String> keys = mpc.getPropertyNames();
    assertEquals(3, keys.size());

    for (String key : keys) {
      assertTrue(key.equals("FOO") || key.equals("DOO") || key.equals("ABC"));
      assertFalse(key.equals("foo") || key.equals("doo") || key.equals("abc"));
    }
  }
예제 #6
0
  @Test
  public void testPropertyScopeOrder() throws Exception {
    MuleEvent e = getTestEvent("testing");
    e.getSession().setProperty("Prop", "session");
    RequestContext.setEvent(e);

    MessagePropertiesContext mpc = new MessagePropertiesContext();
    // Note that we cannot write to the Inbound scope, its read only
    mpc.setProperty("Prop", "invocation", PropertyScope.INVOCATION);
    mpc.setProperty("Prop", "outbound", PropertyScope.OUTBOUND);

    assertEquals("outbound", mpc.getProperty("Prop"));
    mpc.removeProperty("Prop", PropertyScope.OUTBOUND);

    assertEquals("invocation", mpc.getProperty("Prop"));
    mpc.removeProperty("Prop", PropertyScope.INVOCATION);

    assertEquals("session", mpc.getProperty("Prop"));
    assertNull(mpc.getProperty("Prop", PropertyScope.INBOUND));
    assertNull(mpc.getProperty("Prop", PropertyScope.INVOCATION));
    assertNull(mpc.getProperty("Prop", PropertyScope.OUTBOUND));
  }