@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")); } }
@Test public void testsConnection() throws Exception { DbConfig dbConfig = mock(DbConfig.class); TestResult expectedTestResult = mock(TestResult.class); when(dbConfig.test()).thenReturn(expectedTestResult); DbConfigResolver dbConfigResolver = mock(DbConfigResolver.class); when(dbConfigResolver.resolve(null)).thenReturn(dbConfig); MuleRegistry registry = createMockRegistry(dbConfigResolver); DefaultDbConfigResolver defaultDbConfigResolver = new DefaultDbConfigResolver(registry); final TestResult testResult = defaultDbConfigResolver.test(); assertThat(testResult, is(expectedTestResult)); }
@Test public void returnsMetaDataKeys() throws Exception { DbConfig dbConfig = mock(DbConfig.class); final Result<List<MetaDataKey>> expectedMetaDataResult = mock(Result.class); when(dbConfig.getMetaDataKeys()).thenReturn(expectedMetaDataResult); DbConfigResolver dbConfigResolver = mock(DbConfigResolver.class); when(dbConfigResolver.resolve(null)).thenReturn(dbConfig); MuleRegistry registry = createMockRegistry(dbConfigResolver); DefaultDbConfigResolver defaultDbConfigResolver = new DefaultDbConfigResolver(registry); final Result<List<MetaDataKey>> metaDataResult = defaultDbConfigResolver.getMetaDataKeys(); assertThat(metaDataResult, is(expectedMetaDataResult)); }