org.failearly.dataset.internal.resource.DataSetResourceBase.java Source code

Java tutorial

Introduction

Here is the source code for org.failearly.dataset.internal.resource.DataSetResourceBase.java

Source

/*
 * dataSet - Test Support For Datastores.
 *
 * Copyright (C) 2014-2014 Marko Umek (http://fail-early.com/contact)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
package org.failearly.dataset.internal.resource;

import org.apache.commons.lang.StringUtils;
import org.failearly.dataset.DataSet;
import org.failearly.dataset.DataStoreSetup;
import org.failearly.dataset.datastore.DataSetResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * DataSetResourceBase is responsible for ...
 */
abstract class DataSetResourceBase implements DataSetResource {

    final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final String name;

    private final String dataStoreId;

    private final String resourceName;

    private final boolean transactional;

    private final List<String> setupConfigValues;

    private final List<String> cleanupConfigValues;

    private final boolean failOnError;

    DataSetResourceBase(String resourceName, DataSet dataSet) {
        this.resourceName = resourceName;

        this.name = dataSet.name();
        this.dataStoreId = dataSet.datastore();
        this.transactional = dataSet.transactional();
        this.setupConfigValues = Arrays.asList(dataSet.setupConfigValues());
        this.cleanupConfigValues = Arrays.asList(dataSet.cleanupConfigValues());
        this.failOnError = dataSet.failOnError();
    }

    DataSetResourceBase(String resourceName, DataStoreSetup dataStoreSetup) {
        this.resourceName = resourceName;

        this.dataStoreId = dataStoreSetup.datastore();
        this.name = StringUtils.defaultIfEmpty(dataStoreSetup.name(), dataStoreId);
        this.transactional = dataStoreSetup.transactional();
        this.setupConfigValues = Arrays.asList(dataStoreSetup.setupConfigValues());
        this.cleanupConfigValues = Arrays.asList(dataStoreSetup.cleanupConfigValues());
        this.failOnError = dataStoreSetup.failOnError();
    }

    @Override
    public final String name() {
        return this.name;
    }

    @Override
    public final String getDataStoreId() {
        return this.dataStoreId;
    }

    @Override
    public final String getResourceName() {
        return resourceName;
    }

    @Override
    public boolean transactional() {
        return this.transactional;
    }

    @Override
    public final List<String> setupConfigValues() {
        return this.setupConfigValues;
    }

    @Override
    public final List<String> cleanupConfigValues() {
        return this.cleanupConfigValues;
    }

    @Override
    public final boolean failOnError() {
        return this.failOnError;
    }

    @Override
    public String toString() {
        return "DataSetResource{" + "name='" + name + '\'' + ", dataStoreId='" + dataStoreId + '\''
                + ", resourceName='" + resourceName + '\'' + ", transactional=" + transactional
                + ", setupConfigValues=" + setupConfigValues + ", cleanupConfigValues=" + cleanupConfigValues + '}';
    }
}