<commit_before>/**
 * File     : ClusterConfigurationSpec.kt
 * License  :
 *   Original   - Copyright (c) 2015 - 2016 Contrast Security
 *   Derivative - Copyright (c) 2016 Citadel Technology Solutions Pte Ltd
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *           http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.builtamont.cassandra.migration.config

import com.builtamont.cassandra.migration.api.configuration.ClusterConfiguration
import com.builtamont.cassandra.migration.api.configuration.ConfigurationProperty
import io.kotlintest.specs.FreeSpec
import java.nio.file.Paths
import java.util.*

/**
 * ClusterConfiguration unit tests.
 */
class ClusterConfigurationSpec : FreeSpec() {

    val defaultProperties: Properties? = System.getProperties()

    /**
     * Clear test-related System properties.
     */
    fun clearTestProperties() {
        System.clearProperty(ConfigurationProperty.CONTACT_POINTS.namespace)
        System.clearProperty(ConfigurationProperty.PORT.namespace)
        System.clearProperty(ConfigurationProperty.USERNAME.namespace)
        System.clearProperty(ConfigurationProperty.PASSWORD.namespace)
        System.clearProperty(ConfigurationProperty.TRUSTSTORE.namespace)
        System.clearProperty(ConfigurationProperty.TRUSTSTORE_PASSWORD.namespace)
        System.clearProperty(ConfigurationProperty.KEYSTORE.namespace)
        System.clearProperty(ConfigurationProperty.KEYSTORE_PASSWORD.namespace)
    }

    override fun beforeEach() {
        clearTestProperties()
    }

    override fun afterEach() {
        clearTestProperties()
        System.setProperties(defaultProperties)
    }

    init {

        "ClusterConfiguration" - {

            "given default values" - {

                val clusterConfig = ClusterConfiguration()

                "should have default contact points" {
                    clusterConfig.contactpoints.toList() should contain("localhost")
                }

                "should have default port" {
                    clusterConfig.port shouldBe 9042
                }

                "should have no default username" {
                    clusterConfig.username shouldBe null<commit_msg>Updated ClusterConfiguration unit test to pass `127.0.0.1` value<commit_after>/**
 * File     : ClusterConfigurationSpec.kt
 * License  :
 *   Original   - Copyright (c) 2015 - 2016 Contrast Security
 *   Derivative - Copyright (c) 2016 Citadel Technology Solutions Pte Ltd
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *           http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.builtamont.cassandra.migration.config

import com.builtamont.cassandra.migration.api.configuration.ClusterConfiguration
import com.builtamont.cassandra.migration.api.configuration.ConfigurationProperty
import io.kotlintest.specs.FreeSpec
import java.nio.file.Paths
import java.util.*

/**
 * ClusterConfiguration unit tests.
 */
class ClusterConfigurationSpec : FreeSpec() {

    val defaultProperties: Properties? = System.getProperties()

    /**
     * Clear test-related System properties.
     */
    fun clearTestProperties() {
        System.clearProperty(ConfigurationProperty.CONTACT_POINTS.namespace)
        System.clearProperty(ConfigurationProperty.PORT.namespace)
        System.clearProperty(ConfigurationProperty.USERNAME.namespace)
        System.clearProperty(ConfigurationProperty.PASSWORD.namespace)
        System.clearProperty(ConfigurationProperty.TRUSTSTORE.namespace)
        System.clearProperty(ConfigurationProperty.TRUSTSTORE_PASSWORD.namespace)
        System.clearProperty(ConfigurationProperty.KEYSTORE.namespace)
        System.clearProperty(ConfigurationProperty.KEYSTORE_PASSWORD.namespace)
    }

    override fun beforeEach() {
        clearTestProperties()
    }

    override fun afterEach() {
        clearTestProperties()
        System.setProperties(defaultProperties)
    }

    init {

        "ClusterConfiguration" - {

            "given default values" - {

                val clusterConfig = ClusterConfiguration()
                // NOTE: Two hosts for contact points unit test, as in Travis CI the Cassandra hosts are set to
                //       127.0.0.1 for standalone DSE Community and Apache Cassandra, and localhost for embedded
                //       Cassandra.
                val hosts = arrayOf("localhost", "127.0.0.1")

                "should have default contact points" {
                    forAny(hosts) { host ->
                        clusterConfig.contactpoints.toList() should contain(host)
                    }
                }

                "should have default port" {
                    clusterConfig.port shouldBe 9042
                }

                "should have no default username" {
                    clusterConfig.username shouldBe null
{'fraction_non_alphanumeric': 0.07497835497835498, 'fraction_numerical': 0.010043290043290043, 'mean_word_length': 2.7240490006447455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '143644', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1370, 'n_words': 391}