Search in sources :

Example 11 with PersistenceException

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();
}
Also used : CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with PersistenceException

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();
}
Also used : CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Properties(java.util.Properties) Test(org.junit.Test)

Example 13 with PersistenceException

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();
}
Also used : CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with PersistenceException

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();
}
Also used : CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with PersistenceException

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());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Aggregations

PersistenceException (org.apache.ibatis.exceptions.PersistenceException)17 BaseDataTest (org.apache.ibatis.BaseDataTest)6 Test (org.junit.jupiter.api.Test)6 Properties (java.util.Properties)5 RowBounds (org.apache.ibatis.session.RowBounds)5 SqlSession (org.apache.ibatis.session.SqlSession)5 Test (org.junit.Test)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 CorePropertyDefinitions (org.sonar.core.config.CorePropertyDefinitions)5 TaskanaRuntimeException (pro.taskana.exceptions.TaskanaRuntimeException)5 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)2 ClassificationSummary (pro.taskana.ClassificationSummary)2 Duration (java.time.Duration)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Attachment (pro.taskana.Attachment)1 TaskSummary (pro.taskana.TaskSummary)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketSummary (pro.taskana.WorkbasketSummary)1