/*
 * (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 */
package io.cloudslang.lang.tools.build.tester.parse;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * Created by stoneo on 3/15/2015.
 **/
public class SlangTestCase implements Serializable {
    private static final String UNKNOWN_FILE_PATH = "<unknown file path>";

    private String name;

    private String testFlowPath;

    private String description;

    private List<String> testSuites;

    private String systemPropertiesFile;

    @JsonIgnore
    private List<Map> inputs;

    private List<Map> outputs;

    private Boolean throwsException;

    private String result;

    @JsonIgnore
    private String filePath;

    //for jackson
    private SlangTestCase() {
    }

    public SlangTestCase(String name, String testFlowPath, String description, List<String> testSuites,
                         String systemPropertiesFile, List<Map> inputs, List<Map> outputs,
                         Boolean throwsException, String result) {
        this.name = name;
        this.testFlowPath = testFlowPath;
        this.description = description;
        this.systemPropertiesFile = systemPropertiesFile;
        this.testSuites = testSuites;
        this.inputs = inputs;
        this.outputs = outputs;
        this.throwsException = throwsException;
        this.result = result;
        this.filePath = null;
    }

    public SlangTestCase(String name, String testFlowPath, String description, List<String> testSuites,
                         String systemPropertiesFile, List<Map> inputs, List<Map> outputs,
                         Boolean throwsException, String result, String filePath) {
        this.name = name;
        this.testFlowPath = testFlowPath;
        this.description = description;
        this.systemPropertiesFile = systemPropertiesFile;
        this.testSuites = testSuites;
        this.inputs = inputs;
        this.outputs = outputs;
        this.throwsException = throwsException;
        this.result = result;
        this.filePath = filePath;
    }

    public static String generateTestCaseReference(SlangTestCase slangTestCase) {
        return slangTestCase.getName()
                + " ["
                + (StringUtils.isEmpty(slangTestCase.getFilePath()) ? UNKNOWN_FILE_PATH : slangTestCase.getFilePath())
                + "]";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTestFlowPath() {
        return testFlowPath;
    }

    public String getDescription() {
        return description;
    }

    public List<String> getTestSuites() {
        if (CollectionUtils.isEmpty(testSuites)) {
            this.testSuites = new ArrayList<>();
        }
        return testSuites;
    }

    public String getSystemPropertiesFile() {
        return systemPropertiesFile;
    }

    public void setInputs(List<Map> inputs) {
        this.inputs = inputs;
    }

    public List<Map> getInputs() {
        return inputs;
    }

    public List<Map> getOutputs() {
        return outputs;
    }

    public Boolean getThrowsException() {
        return throwsException;
    }

    public void setThrowsException(boolean throwsException) {
        this.throwsException = throwsException;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
    }


    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }
}

@@ -439,56 +439,82 @@
 ort 
-java.io.Serializable;%0Aimport java.util.ArrayList
+io.cloudslang.lang.tools.build.SlangBuildMain;%0Aimport java.io.Serializable
 ;%0Aim
@@ -586,31 +586,20 @@
 ons.
-collections4.Collection
+lang3.String
 Util
@@ -629,35 +629,45 @@
 mmons.lang3.
-StringUtils
+builder.EqualsBuilder
 ;%0Aimport org
@@ -688,38 +688,40 @@
 s.lang3.builder.
-Equals
+HashCode
 Builder;%0Aimport 
@@ -717,63 +717,138 @@
 er;%0A
+%0A
 import 
-org.apache.commons.lang3.builder.HashCodeBuilder
+static com.google.common.collect.Lists.newArrayList;%0Aimport static org.apache.commons.collections4.CollectionUtils.isEmpty
 ;%0A%0A/
@@ -3368,36 +3368,44 @@
     
-if (CollectionUtils.isEmpty(
+List%3CString%3E localTestSuites = this.
 test
@@ -3414,12 +3414,9 @@
 ites
-)) %7B
+;
 %0A   
@@ -3416,34 +3416,45 @@
 es;%0A        
-    this.t
+return isEmpty(localT
 estSuites = 
@@ -3454,15 +3454,15 @@
 ites
- =
+) ?
  new
- 
 Arra
@@ -3470,40 +3470,60 @@
 List
-%3C%3E();%0A        %7D%0A        return t
+(SlangBuildMain.DEFAULT_TESTS) : newArrayList(localT
 estS
@@ -3523,24 +3523,25 @@
 alTestSuites
+)
 ;%0A    %7D%0A%0A   
@@ -3529,32 +3529,33 @@
 Suites);%0A    %7D%0A%0A
+%0A
     public Strin

fix default test suite difference between not declared and declared explicitly