use of org.apache.ibatis.exceptions.PersistenceException in project sonarqube by SonarSource.
the class ThreadLocalSettingsTest method getProperties_return_properties_from_previous_thread_cache_if_DB_error_on_not_first_call.
@Test
public void getProperties_return_properties_from_previous_thread_cache_if_DB_error_on_not_first_call() {
String key = randomAlphanumeric(3);
String value1 = randomAlphanumeric(4);
String value2 = randomAlphanumeric(5);
SettingLoader settingLoaderMock = mock(SettingLoader.class);
PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
doAnswer(invocationOnMock -> ImmutableMap.of(key, value1)).doThrow(toBeThrown).doAnswer(invocationOnMock -> ImmutableMap.of(key, value2)).when(settingLoaderMock).loadAll();
underTest = new ThreadLocalSettings(new PropertyDefinitions(system), new Properties(), settingLoaderMock);
underTest.load();
assertThat(underTest.getProperties()).containsOnly(entry(key, value1));
underTest.unload();
underTest.load();
assertThat(underTest.getProperties()).containsOnly(entry(key, value1));
underTest.unload();
underTest.load();
assertThat(underTest.getProperties()).containsOnly(entry(key, value2));
underTest.unload();
}
use of org.apache.ibatis.exceptions.PersistenceException in project sonarqube by SonarSource.
the class ThreadLocalSettingsTest method get_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache.
@Test
public void get_returns_empty_if_DB_error_on_first_call_ever_in_thread_cache() {
SettingLoader settingLoaderMock = mock(SettingLoader.class);
PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
String key = randomAlphanumeric(3);
doThrow(toBeThrown).when(settingLoaderMock).load(key);
underTest = new ThreadLocalSettings(new PropertyDefinitions(system), new Properties(), settingLoaderMock);
underTest.load();
assertThat(underTest.get(key)).isEmpty();
}
use of org.apache.ibatis.exceptions.PersistenceException in project sonarqube by SonarSource.
the class ThreadLocalSettingsTest method getProperties_return_empty_if_DB_error_on_first_call_ever_out_of_thread_cache.
@Test
public void getProperties_return_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() {
SettingLoader settingLoaderMock = mock(SettingLoader.class);
PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
doThrow(toBeThrown).when(settingLoaderMock).loadAll();
underTest = new ThreadLocalSettings(new PropertyDefinitions(system), new Properties(), settingLoaderMock);
assertThat(underTest.getProperties()).isEmpty();
}
use of org.apache.ibatis.exceptions.PersistenceException in project sonarqube by SonarSource.
the class ThreadLocalSettingsTest method get_returns_empty_if_DB_error_on_first_call_ever_out_of_thread_cache.
@Test
public void get_returns_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() {
SettingLoader settingLoaderMock = mock(SettingLoader.class);
PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
String key = randomAlphanumeric(3);
doThrow(toBeThrown).when(settingLoaderMock).load(key);
underTest = new ThreadLocalSettings(new PropertyDefinitions(system), new Properties(), settingLoaderMock);
assertThat(underTest.get(key)).isEmpty();
}
use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.
the class ForEachTest method shouldNotAllowNullWhenAttributeIsOmitAndConfigurationIsFalse.
@Test
void shouldNotAllowNullWhenAttributeIsOmitAndConfigurationIsFalse() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
sqlSessionFactory.getConfiguration().setNullableOnForEach(false);
Mapper mapper = sqlSession.getMapper(Mapper.class);
User user = new User();
user.setFriendList(null);
mapper.countUserWithNullableIsOmit(user);
Assertions.fail();
} catch (PersistenceException e) {
Assertions.assertEquals("The expression 'friendList' evaluated to a null value.", e.getCause().getMessage());
}
}
Aggregations