<commit_before>/*
 * Sakuli - Testing and Monitoring-Tool for Websites and common UIs.
 *
 * Copyright 2013 - 2014 the original author or authors.
 *
 * 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 de.consol.sakuli.datamodel;

import de.consol.sakuli.datamodel.properties.TestSuiteProperties;
import de.consol.sakuli.datamodel.state.TestCaseState;
import de.consol.sakuli.datamodel.state.TestSuiteState;
import de.consol.sakuli.exceptions.SakuliException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.nio.file.Path;
import java.util.*;

/**
 * @author tschneck Date: 10.06.13
 */
@Component
public class TestSuite extends AbstractTestDataEntity<SakuliException, TestSuiteState> {

    //browser name where to start the test execution
    private String browserName;
    //additional browser infos from sahi proxy
    private String browserInfo;
    private String host;
    private Path testSuiteFolder;
    private Path testSuiteFile;
    private int dbJobPrimaryKey = -1;
    private Map<String, TestCase> testCases;
    private boolean uiTest = false;

    public TestSuite() {
    }

    @Autowired
    public TestSuite(TestSuiteProperties properties) {
        id = properties.getTestSuiteId();
        name = properties.getTestSuiteName();
        //if name is not set, use the id
        if (StringUtils.isEmpty(name)) {
            name = id;
        }
        warningTime = properties.getWarningTime();
        criticalTime = properties.getCriticalTime();
        testSuiteFolder = properties.getTestSuiteFolder();
        testSuiteFile = properties.getTestSuiteSuiteFile();
        browserName = properties.getBrowserName();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public void refreshState() {
        if (exception != null) {
            state = TestSuiteState.ERRORS;
        } else if (testCases == null) {
            state = TestSuiteState.RUNNING;
        } else {
            for (TestCase tc : testCases.values()) {
                //if at least on test case has no finished, test suite is still running!
                if (tc.getStopDate() == null) {
                    state = TestSuiteState.RUNNING;
                    return;
                }

                tc.refreshState();
                if (tc.getState() == null) {
                    tc.addException(new SakuliException("ERROR: NO RESULT STATE SET"));
                    state = TestSuiteState.ERRORS;
                } else if (tc.getState().equals(TestCaseState.ERRORS)) {
                    state = TestSuiteState.ERRORS;
                } else if (tc.getState().equals(TestCaseState.CRITICAL)
                        && state.getErrorCode() < TestSuiteState.CRITICAL_IN_CASE.getErrorCode()) {
                    state = TestSuiteState.CRITICAL_IN_CASE;
                } else if (tc.getState().equals(TestCaseState.WARNING)
                        && state.getErrorCode() < TestSuiteState.WARNING_IN_CASE.getErrorCode()) {
                    state = TestSuiteState.WARNING_IN_CASE;
                } else if (tc.getState().equals(TestCaseState.WARNING_IN_STEP)
                        && state.getErrorCode() < TestSuiteState.WARNING_IN_STEP.getErrorCode()) {
                    state = TestSuiteState.WARNING_IN_STEP;
                } else if (tc.getState().equals(TestCaseState.OK)
                        && state.getErrorCode() < TestSuiteState.OK.getErrorCode()) {<commit_msg>check error code before stopdate for state refreshing // add some comments<commit_after>/*
 * Sakuli - Testing and Monitoring-Tool for Websites and common UIs.
 *
 * Copyright 2013 - 2014 the original author or authors.
 *
 * 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 de.consol.sakuli.datamodel;

import de.consol.sakuli.datamodel.properties.TestSuiteProperties;
import de.consol.sakuli.datamodel.state.TestCaseState;
import de.consol.sakuli.datamodel.state.TestSuiteState;
import de.consol.sakuli.exceptions.SakuliException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.nio.file.Path;
import java.util.*;

/**
 * @author tschneck Date: 10.06.13
 */
@Component
public class TestSuite extends AbstractTestDataEntity<SakuliException, TestSuiteState> {

    //browser name where to start the test execution
    private String browserName;
    //additional browser infos from sahi proxy
    private String browserInfo;
    private String host;
    private Path testSuiteFolder;
    private Path testSuiteFile;
    private int dbJobPrimaryKey = -1;
    private Map<String, TestCase> testCases;
    private boolean uiTest = false;

    public TestSuite() {
    }

    @Autowired
    public TestSuite(TestSuiteProperties properties) {
        id = properties.getTestSuiteId();
        name = properties.getTestSuiteName();
        //if name is not set, use the id
        if (StringUtils.isEmpty(name)) {
            name = id;
        }
        warningTime = properties.getWarningTime();
        criticalTime = properties.getCriticalTime();
        testSuiteFolder = properties.getTestSuiteFolder();
        testSuiteFile = properties.getTestSuiteSuiteFile();
        browserName = properties.getBrowserName();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public void refreshState() {
        if (exception != null) {
            state = TestSuiteState.ERRORS;
        } else if (testCases == null) {
            state = TestSuiteState.RUNNING;
        } else {
            for (TestCase tc : testCases.values()) {
                tc.refreshState();

                //if errors are found suite state is always error!
                if (tc.getState() == null) {
                    tc.addException(new SakuliException("ERROR: NO RESULT STATE SET"));
                    state = TestSuiteState.ERRORS;
                } else if (tc.getState().equals(TestCaseState.ERRORS)) {
                    state = TestSuiteState.ERRORS;
                }
                //if at least on test case has not finished, test suite is still running!
                else if (tc.getStopDate() == null) {
                    state = TestSuiteState.RUNNING;
                    return;
                }
                //now check if thresholds didn't exceed
                else if (tc.getState().equals(TestCaseState.CRITICAL)
                        && state.getErrorCode() < TestSuiteState.CRITICAL_IN_CASE.getErrorCode()) {
                    state = TestSuiteState.CRITICAL_IN_CASE;
                } else if (tc.getState().equals(TestCaseState.WARNING)
                        && state.getErrorCode() < TestSuiteState.WARNING_IN_CASE.getErrorCode()) {
                    state = TestSuiteState.WARNING_IN_CASE;
                } else if (tc.getState().equals(TestCaseState.WARNING_IN_STEP)
                        && state.getErrorCode() < TestSuiteState.WARNING_IN_STEP.getErrorCode()) {
                    state = TestSuiteState.WARNING_IN_STEP;
                }
                //all thresholds ok, no errors, case finished
                else if (tc.getState().equals(TestCaseState.OK)
                        && state.getErrorCode() < TestSuiteState.OK.getErrorCode()) {
{'fraction_non_alphanumeric': 0.09138134592680047, 'fraction_numerical': 0.00448642266824085, 'mean_word_length': 2.4309437019036046, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '4553447', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2194, 'n_words': 605}