コード例 #1
0
  @Test
  public void throwsErrorWhenMultipleDbConfigAvailable() throws Exception {
    DbConfig dbConfig1 = mock(DbConfig.class);
    when(dbConfig1.getName()).thenReturn("dbConfig1");
    DbConfig dbConfig2 = mock(DbConfig.class);
    when(dbConfig2.getName()).thenReturn("dbConfig2");

    DbConfigResolver dbConfigResolver1 = mock(DbConfigResolver.class);
    when(dbConfigResolver1.resolve(null)).thenReturn(dbConfig1);

    DbConfigResolver dbConfigResolver2 = mock(DbConfigResolver.class);
    when(dbConfigResolver2.resolve(null)).thenReturn(dbConfig2);

    MuleRegistry registry = mock(MuleRegistry.class);
    Collection<DbConfigResolver> foundDbConfigResolvers = new ArrayList<>();
    foundDbConfigResolvers.add(dbConfigResolver1);
    foundDbConfigResolvers.add(dbConfigResolver2);

    when(registry.lookupObjects(DbConfigResolver.class)).thenReturn(foundDbConfigResolvers);

    DefaultDbConfigResolver dbConfigResolver = new DefaultDbConfigResolver(registry);

    try {
      dbConfigResolver.resolve(muleEvent);
      fail("Was supposed to fail when there are multiple dbConfigs available");
    } catch (UnresolvableDbConfigException e) {
      assertThat(e.getMessage(), containsString("dbConfig1"));
      assertThat(e.getMessage(), containsString("dbConfig2"));
    }
  }
コード例 #2
0
  private MuleRegistry createMockRegistry(DbConfigResolver dbConfigResolver) {
    Collection<DbConfigResolver> foundDbConfigResolvers = new ArrayList<>();
    foundDbConfigResolvers.add(dbConfigResolver);

    MuleRegistry registry = mock(MuleRegistry.class);
    when(registry.lookupObjects(DbConfigResolver.class)).thenReturn(foundDbConfigResolvers);

    return registry;
  }
コード例 #3
0
  @Test(expected = UnresolvableDbConfigException.class)
  public void throwsErrorWhenNoDbConfigAvailable() throws Exception {
    MuleRegistry registry = mock(MuleRegistry.class);
    Collection<DbConfig> foundDbConfigs = new ArrayList<DbConfig>();

    when(registry.lookupObjects(DbConfig.class)).thenReturn(foundDbConfigs);

    DefaultDbConfigResolver dbConfigResolver = new DefaultDbConfigResolver(registry);

    dbConfigResolver.resolve(muleEvent);
  }
コード例 #4
0
  @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"));
  }