<commit_before>/*
 * Copyright 2013 Netflix, Inc.
 *
 * 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.netflix.asgard

import grails.converters.XML
import groovy.util.slurpersupport.GPathResult
import groovy.xml.MarkupBuilder
import spock.lang.Specification

class FastPropertySpec extends Specification {

    private FastProperty constructFastProperty(String key, String value, String env, String appId, String regionCode, String stack, String countries,
                String updatedBy, String sourceOfUpdate, String cmcTicket) {
        StringWriter writer = new StringWriter()
        final MarkupBuilder builder = new MarkupBuilder(writer)
        builder.property {
            builder.key(key)
            builder.value(value)
            builder.env(env)
            builder.appId(appId)
            builder.region(regionCode)
            builder.stack(stack)
            builder.countries(countries)
            builder.updatedBy(updatedBy)
            builder.sourceOfUpdate(sourceOfUpdate)
            builder.cmcTicket(cmcTicket)
        }
        String xmlString = writer.toString()
        GPathResult xml = XML.parse(xmlString) as GPathResult
        FastProperty.fromXml(xml)
    }

    def 'should construct fast property with all values'() {
        FastProperty actualFastProperty = constructFastProperty('dial', '11', 'test', 'tap', 'eu-west-1', 'spinal',
                'UK', 'cmccoy', 'asgard', '123')
        FastProperty expectedFastProperty = new FastProperty(key: 'dial', value: '11', env: 'test', appId: 'tap',
                region: 'eu-west-1', stack: 'spinal', countries: 'UK', updatedBy: 'cmccoy', sourceOfUpdate: 'asgard',
                cmcTicket: '123')

        expect:
        actualFastProperty == expectedFastProperty
        actualFastProperty.id == 'dial|tap|test|eu-west-1||spinal|UK'
    }

    def 'should construct fast property missing optional values'() {
        FastProperty actualFastProperty = constructFastProperty('dial', '11', 'test', 'tap', 'eu-west-1', null,
                null, null, null, null)
        FastProperty expectedFastProperty = new FastProperty(key: 'dial', value: '11', env: 'test', appId: 'tap',
                region: 'eu-west-1')

        expect:
        actualFastProperty == expectedFastProperty
        actualFastProperty.id == 'dial|tap|test|eu-west-1|||'
    }

    def 'should construct id for valid values'() {
        FastProperty fastProperty = constructFastProperty('dial', '11', 'test', 'tap', 'eu-west-1', 'spinal',
                'UK', 'cmccoy', 'asgard', '123')

        expect:
        fastProperty.id == 'dial|tap|test|eu-west-1||spinal|UK'
    }

    def 'should construct id for invalid values'() {
        FastProperty fastProperty = constructFastProperty('_dial_', '11?', 'test:', '*tap*', 'eu-west-1', '!spinal!',
                'UK', 'cmccoy', 'asgard', '123')

        expect:
        fastProperty.id == '_dial_|*tap*|test:|eu-west-1||!spinal!|UK'
    }
}
<commit_msg>use simplified FastProperty construction in tests<commit_after>/*
 * Copyright 2013 Netflix, Inc.
 *
 * 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.netflix.asgard

import grails.converters.XML
import groovy.util.slurpersupport.GPathResult
import groovy.xml.MarkupBuilder
import spock.lang.Specification

class FastPropertySpec extends Specification {

    private FastProperty constructFastProperty(String key, String value, String env, String appId, String regionCode, String stack, String countries,
                String updatedBy, String sourceOfUpdate, String cmcTicket) {
        StringWriter writer = new StringWriter()
        final MarkupBuilder builder = new MarkupBuilder(writer)
        builder.property {
            builder.key(key)
            builder.value(value)
            builder.env(env)
            builder.appId(appId)
            builder.region(regionCode)
            builder.stack(stack)
            builder.countries(countries)
            builder.updatedBy(updatedBy)
            builder.sourceOfUpdate(sourceOfUpdate)
            builder.cmcTicket(cmcTicket)
        }
        String xmlString = writer.toString()
        GPathResult xml = XML.parse(xmlString) as GPathResult
        FastProperty.fromXml(xml)
    }

    def 'should construct fast property with all values'() {
        FastProperty actualFastProperty = constructFastProperty('dial', '11', 'test', 'tap', 'eu-west-1', 'spinal',
                'UK', 'cmccoy', 'asgard', '123')
        FastProperty expectedFastProperty = new FastProperty(key: 'dial', value: '11', env: 'test', appId: 'tap',
                region: 'eu-west-1', stack: 'spinal', countries: 'UK', updatedBy: 'cmccoy', sourceOfUpdate: 'asgard',
                cmcTicket: '123')

        expect:
        actualFastProperty == expectedFastProperty
        actualFastProperty.id == 'dial|tap|test|eu-west-1||spinal|UK'
    }

    def 'should construct fast property missing optional values'() {
        FastProperty actualFastProperty = constructFastProperty('dial', '11', 'test', 'tap', 'eu-west-1', null,
                null, null, null, null)
        FastProperty expectedFastProperty = new FastProperty(key: 'dial', value: '11', env: 'test', appId: 'tap',
                region: 'eu-west-1')

        expect:
        actualFastProperty == expectedFastProperty
        actualFastProperty.id == 'dial|tap|test|eu-west-1|||'
    }

    def 'should construct id for valid values'() {
        expect:
        new FastProperty(key: 'dial', env: 'test', appId: 'tap', region: 'eu-west-1', stack: 'spinal', countries: 'UK',
                serverId: 'server1').id == 'dial|tap|test|eu-west-1|server1|spinal|UK'
    }

    def 'should construct id for invalid values'() {
        expect:
        new FastProperty(key: '_dial_', env: 'test:', appId: '*tap*', region: 'eu-west-1', stack: '!spinal!',
                countries: 'UK').id == '_dial_|*tap*|test:|eu-west-1||!spinal!|UK'
    }
}

{'fraction_non_alphanumeric': 0.11647278471923021, 'fraction_numerical': 0.010914835559385322, 'mean_word_length': 2.9523269012485813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, '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': '4328020', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1919, 'n_words': 563}