<commit_before>/*
 * CollabNet Subversion Edge
 * Copyright (C) 2011, CollabNet Inc. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.collabnet.svnedge.replication.command

import com.collabnet.svnedge.domain.Server

import com.collabnet.svnedge.integration.command.AbstractCommand
import com.collabnet.svnedge.integration.command.CommandsExecutionContext

import com.collabnet.svnedge.util.ConfigUtil
import grails.test.GrailsUnitTestCase

import com.collabnet.svnedge.domain.integration.*

class CopyRevpropsCommandIntegrationTests extends GrailsUnitTestCase {

    def replicaCommandExecutorService
    def commandLineService
    def securityService
    def jobsAdminService
    def grailsApplication
    def config

    def REPO_NAME = "testproject2"
    def EXSY_ID = "exsy9876"
    def rConf
    File repoParentDir
    CommandsExecutionContext executionContext

    public CopyRevpropsCommandIntegrationTests() {
        this.rConf = ReplicaConfiguration.getCurrentConfig()
        if (!this.rConf) {
            rConf = new ReplicaConfiguration(svnMasterUrl: null,
                name: "Test Replica", description: "Super replica",
                message: "Auto-approved", systemId: "replica1001",
                commandPollRate: 5, approvalState: ApprovalState.APPROVED)
            this.rConf.save()
        }
        // Setup a test repository parent
        repoParentDir = createTestDir("repo")
    }

    protected void tearDown() {
        super.tearDown()
        repoParentDir.deleteDir()

        // delete any log file
        AbstractCommand.getExecutionLogFile(executionContext)?.delete()
    }

    protected void setUp() {
        super.setUp()

        assertNotNull("The replica instance must exist", this.rConf)
        this.config = grailsApplication.config
        this.rConf.svnMasterUrl = makeCtfBaseUrl() + "/svn/repos"
        this.rConf.save()

        Server server = Server.getServer()
        server.repoParentDir = repoParentDir.getCanonicalPath()
        server.save()

        // delete the repo directory for the repo we are adding.
        def repoFileDir = new File(repoParentDir, REPO_NAME)
        repoFileDir.deleteDir()

        CtfServer ctfServer = CtfServer.getServer()
        ctfServer.baseUrl = makeCtfBaseUrl()
        ctfServer.mySystemId = EXSY_ID
        ctfServer.ctfUsername = "admin"
        ctfServer.ctfPassword = "<PASSWORD>="
        ctfServer.save()

        executionContext = new CommandsExecutionContext()
        executionContext.logsDir = System.getProperty("java.io.tmpdir")
        executionContext.appContext = grailsApplication.mainContext
    }

    private def makeCtfBaseUrl() {
        def ctfProto = config.svnedge.ctfMaster.ssl ? "https://" : "http://"
        def ctfHost = config.svnedge.ctfMaster.domainName
        def ctfPort = config.svnedge.ctfMaster.port == "80" ? "" : ":" +
                config.svnedge.ctfMaster.port
        return ctfProto + ctfHost + ctfPort
    }


    public void testSyncRevprops() {
        def classLoader = getClass().getClassLoader()

        def revNumberToAlter
        def originalCommitMsg = "ORIGINAL commit msg"
        def updatedCommitMsg = "UPDATED commit msg"

        def cmdParams = [:]
        cmdParams["repoName"] = REPO_NAME
        cmdParams["masterId"] = EXSY_ID

        // add and sync the repo
        def commandMap = [code: 'repoAdd', id: 0, params: cmdParams, 
            context: executionContext]
        def command = AbstractCommand.makeCommand(classLoader, commandMap)
        replicaCommandExecutorService.commandLifecycleExecutor(command)
<commit_msg>[artf5797] : svnedge: implement revprop sync command<commit_after>/*
 * CollabNet Subversion Edge
 * Copyright (C) 2011, CollabNet Inc. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.collabnet.svnedge.replication.command

import com.collabnet.svnedge.domain.Server

import com.collabnet.svnedge.integration.command.AbstractCommand
import com.collabnet.svnedge.integration.command.CommandsExecutionContext

import com.collabnet.svnedge.util.ConfigUtil
import grails.test.GrailsUnitTestCase

import com.collabnet.svnedge.domain.integration.*

class CopyRevpropsCommandIntegrationTests extends GrailsUnitTestCase {

    def replicaCommandExecutorService
    def commandLineService
    def securityService
    def jobsAdminService
    def grailsApplication
    def config

    def REPO_NAME = "testproject2"
    def EXSY_ID = "exsy9876"
    def rConf
    File repoParentDir
    CommandsExecutionContext executionContext

    public CopyRevpropsCommandIntegrationTests() {
        this.rConf = ReplicaConfiguration.getCurrentConfig()
        if (!this.rConf) {
            rConf = new ReplicaConfiguration(svnMasterUrl: null,
                name: "Test Replica", description: "Super replica",
                message: "Auto-approved", systemId: "replica1001",
                commandPollRate: 5, approvalState: ApprovalState.APPROVED)
            this.rConf.save()
        }
        // Setup a test repository parent
        repoParentDir = createTestDir("repo")
    }

    protected void tearDown() {
        super.tearDown()
        repoParentDir.deleteDir()

        // delete any log file
        AbstractCommand.getExecutionLogFile(executionContext)?.delete()
    }

    protected void setUp() {
        super.setUp()

        assertNotNull("The replica instance must exist", this.rConf)
        this.config = grailsApplication.config
        this.rConf.svnMasterUrl = makeCtfBaseUrl() + "/svn/repos"
        this.rConf.save(flush:true)

        Server server = Server.getServer()
        server.repoParentDir = repoParentDir.getCanonicalPath()
        server.save(flush:true)

        // delete the repo directory for the repo we are adding.
        def repoFileDir = new File(repoParentDir, REPO_NAME)
        repoFileDir.deleteDir()

        CtfServer ctfServer = CtfServer.getServer()
        ctfServer.baseUrl = makeCtfBaseUrl()
        ctfServer.mySystemId = EXSY_ID
        ctfServer.ctfUsername = "admin"
        ctfServer.ctfPassword = "<PASSWORD>="
        ctfServer.save(flush:true)

        executionContext = new CommandsExecutionContext()
        executionContext.logsDir = System.getProperty("java.io.tmpdir")
        executionContext.appContext = grailsApplication.mainContext
    }

    private def makeCtfBaseUrl() {
        def ctfProto = config.svnedge.ctfMaster.ssl ? "https://" : "http://"
        def ctfHost = config.svnedge.ctfMaster.domainName
        def ctfPort = config.svnedge.ctfMaster.port == "80" ? "" : ":" +
                config.svnedge.ctfMaster.port
        return ctfProto + ctfHost + ctfPort
    }


    public void testSyncRevprops() {
        def classLoader = getClass().getClassLoader()

        def revNumberToAlter
        def originalCommitMsg = "ORIGINAL commit msg"
        def updatedCommitMsg = "UPDATED commit msg"

        def cmdParams = [:]
        cmdParams["repoName"] = REPO_NAME
        cmdParams["masterId"] = EXSY_ID

        // add and sync the repo
        assertNotNull("ReplicaConfig must have svnMasterUrl from which to sync",
                ReplicaConfiguration.getCurrentConfig().svnMasterUrl)
        def commandMap = [code: 'repoAdd', id: 0, params: cmdParams, 
            context: executionContext]
        def command = AbstractCommand.makeCommand(classLoader, commandMap)
        replicaCommandExecutorService.commandLifecycleExecutor(command)

{'fraction_non_alphanumeric': 0.08075955159002517, 'fraction_numerical': 0.004575611988103409, 'mean_word_length': 2.9849589790337285, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '1469888', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2392, 'n_words': 652}