/*
 * Copyright 2019, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.storage.jdbc;

import io.spine.server.storage.jdbc.GivenDataSource.ThrowingHikariDataSource;
import io.spine.testing.logging.MuteLogging;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static io.spine.base.Identifier.newUuid;
import static io.spine.server.storage.jdbc.GivenDataSource.whichIsThrowingByCommand;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("DataSourceWrapper should")
class DataSourceWrapperTest {

    @Test
    @MuteLogging
    @DisplayName("throw `DatabaseException` if failing to close")
    void throwIfFailToClose() {
        ThrowingHikariDataSource dataSource = whichIsThrowingByCommand(newUuid());
        dataSource.setThrowOnClose(true);
        DataSourceWrapper wrapper = DataSourceWrapper.wrap(dataSource);
        assertThrows(DatabaseException.class, wrapper::close);
    }
}

@@ -1264,40 +1264,178 @@
 tic 
-io.spine.base.Identifier.newUuid
+com.google.common.truth.Truth.assertThat;%0Aimport static io.spine.base.Identifier.newUuid;%0Aimport static io.spine.server.storage.jdbc.GivenDataSource.whichIsStoredInMemory
 ;%0Aim
@@ -1517,16 +1517,85 @@
 ommand;%0A
+import static io.spine.server.storage.jdbc.PredefinedMapping.H2_1_4;%0A
 import s
@@ -1940,174 +1940,1438 @@
     
-dataSource.setThrowOnClose(true);%0A        DataSourceWrapper wrapper = DataSourceWrapper.wrap(dataSource);%0A        assertThrows(DatabaseException.class, wrapper::close
+DataSourceWrapper wrapper = DataSourceWrapper.wrap(dataSource);%0A        dataSource.setThrowOnClose(true);%0A        assertThrows(DatabaseException.class, wrapper::close);%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22provide database meta data%22)%0A    void returnMetaData() %7B%0A        DataSourceWrapper dataSourceWrapper = whichIsStoredInMemory(newUuid());%0A        DataSourceMetaData metaData = dataSourceWrapper.metaData();%0A%0A        assertThat(metaData.productName())%0A                .isEqualTo(H2_1_4.getDatabaseProductName());%0A        assertThat(metaData.majorVersion())%0A                .isEqualTo(H2_1_4.getMajorVersion());%0A        assertThat(metaData.minorVersion())%0A                .isEqualTo(H2_1_4.getMinorVersion());%0A    %7D%0A%0A    @Test%0A    @MuteLogging%0A    @DisplayName(%22throw %60DatabaseException%60 if failed to obtain a meta data%22)%0A    void throwOnGetMetaDataError() %7B%0A        ThrowingHikariDataSource dataSource = whichIsThrowingByCommand(newUuid());%0A        DataSourceWrapper wrapper = DataSourceWrapper.wrap(dataSource);%0A        dataSource.setThrowOnGetConnection(true);%0A%0A        assertThrows(DatabaseException.class, wrapper::metaData);%0A    %7D%0A%0A    @Test%0A    @DisplayName(%22throw ISE if obtaining meta data when already closed%22)%0A    void throwIseIfAlreadyClosed() %7B%0A        DataSourceWrapper dataSource = whichIsStoredInMemory(newUuid());%0A        dataSource.close();%0A%0A        assertThrows(IllegalStateException.class, dataSource::metaData
 );%0A 

Add tests for `DataSourceWrapper` returning meta data