<commit_before>/*
* CollabNet Subversion Edge
* Copyright (C) 2010, 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.teamforge

import groovy.lang.MetaClass;

import com.collabnet.svnedge.AbstractSvnEdgeFunctionalTests;
import com.collabnet.svnedge.console.Repository;
import com.collabnet.svnedge.console.security.User;
import com.collabnet.svnedge.statistics.StatValue;

/**
* This is an abstract class for the conversion process that provides the 
* "heavy-lifting" of the steps performed on the Web UI.
*
* @author <NAME> (<EMAIL>)
*
*/
abstract class AbstractConversionFunctionalTests extends 
    AbstractSvnEdgeFunctionalTests {

    /**
     * It is the test URL based on the properties in the Config.groovy
     */
    def ctfTestUrl

    def ctfRemoteClientService

    @Override
    protected void setUp() {
        super.setUp();

        //running on a machine that does not have a name does not work.
        if (server.hostname == "localhost" || server.hostname == "127.0.0.1") {
            return
        }

        // setup the csvn image for testing the software version during 
        // conversion
        this.setupTestCsvnImage()

        // remove any repository created
        this.cleanRepositories()

        // convert if necessary
        this.convertToStandaloneMode()

        // verify that the links to teamForge mode are prohibited.
        this.assertProhibitedAccessToTeamForgeModeLinksWorks()
    }

    @Override
    protected void tearDown() {
        this.convertToStandaloneMode()
        super.tearDown();
    }

    /**
     * Removes all the references of repositories from the database. It also
     * includes removing the references to statistics values from the db.
     */
    protected void cleanRepositories() {
        StatValue.list().each{
            it.delete(flush:true)
        }
        Repository.list().each {
            it.delete(flush:true)
        }
    }

    /**
     * Deletes the project created during the conversion process.
     */
    protected void removeProjectFromCtfServer() {
        def username = config.svnedge.ctfMaster.username
        def password = config.svnedge.ctfMaster.password
        def cnSoap = ctfRemoteClientService.cnSoap(this.getTestCtfUrl())
        def sessionId = cnSoap.login(username, password)

        def projects = ctfRemoteClientService.getProjectList(
            this.getTestCtfUrl(), sessionId)
        String projectId = null
        for (p in projects) {
            if (this.createdProjectName == p.title.toLowerCase()) {
                projectId = p.id
                break<commit_msg>Clean up repositories created in functional testing<commit_after>/*
* CollabNet Subversion Edge
* Copyright (C) 2010, 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.teamforge

import groovy.lang.MetaClass;

import com.collabnet.svnedge.AbstractSvnEdgeFunctionalTests;
import com.collabnet.svnedge.console.Repository;
import com.collabnet.svnedge.console.Server;
import com.collabnet.svnedge.console.security.User;
import com.collabnet.svnedge.statistics.StatValue;

/**
* This is an abstract class for the conversion process that provides the 
* "heavy-lifting" of the steps performed on the Web UI.
*
* @author <NAME> (<EMAIL>)
*
*/
abstract class AbstractConversionFunctionalTests extends 
    AbstractSvnEdgeFunctionalTests {

    /**
     * It is the test URL based on the properties in the Config.groovy
     */
    def ctfTestUrl

    def ctfRemoteClientService

    @Override
    protected void setUp() {
        super.setUp();

        //running on a machine that does not have a name does not work.
        if (server.hostname == "localhost" || server.hostname == "127.0.0.1") {
            return
        }

        // setup the csvn image for testing the software version during 
        // conversion
        this.setupTestCsvnImage()

        // remove any repository created
        this.cleanRepositories()

        // convert if necessary
        this.convertToStandaloneMode()

        // verify that the links to teamForge mode are prohibited.
        this.assertProhibitedAccessToTeamForgeModeLinksWorks()
    }

    @Override
    protected void tearDown() {
        this.convertToStandaloneMode()
        this.cleanRepositories()
        super.tearDown();
    }

    /**
     * Removes all the references of repositories from the database. It also
     * includes removing the references to statistics values from the db.
     */
    protected void cleanRepositories() {
        StatValue.list().each{
            it.delete(flush:true)
        }
        def repoParentDir = Server.getServer().repoParentDir
        Repository.list().each {
            File f = new File(repoParentDir, it.name)
            if (f.exists()) {
                f.deleteDir()
            }
            it.delete(flush:true)
        }
    }

    /**
     * Deletes the project created during the conversion process.
     */
    protected void removeProjectFromCtfServer() {
        def username = config.svnedge.ctfMaster.username
        def password = config.svnedge.ctfMaster.password
        def cnSoap = ctfRemoteClientService.cnSoap(this.getTestCtfUrl())
        def sessionId = cnSoap.login(username, password)

        def projects = ctfRemoteClientService.getProjectList(
            this.getTestCtfUrl(), sessionId)
        String projectId = null
        for (p in projects) {
            if (this.createdProjectName == p.title.toLowerCase()) {
                projectId = p.id
                break
{'fraction_non_alphanumeric': 0.07921945536624436, 'fraction_numerical': 0.003203727974370176, 'mean_word_length': 2.694459386767079, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '6991894', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1829, 'n_words': 623}