Fix sonar blocker in ChefAdpater
[appc.git] / appc-asdc-listener / appc-asdc-listener-bundle / src / main / resources / ci / scripts / startTest.sh
1 ###
2 # ============LICENSE_START=======================================================
3 # ONAP : APPC
4 # ================================================================================
5 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 # ================================================================================
7 # Copyright (C) 2017 Amdocs
8 # =============================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12
13 #      http://www.apache.org/licenses/LICENSE-2.0
14
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 # ============LICENSE_END=========================================================
23 ###
24
25 #!/bin/bash
26
27 function usage {
28         echo "Usage: $0 <jar file>"
29 }
30
31 function exitOnError() {
32         if [ $1 -ne 0 ]
33         then
34                 echo "Failed running task $2"
35                 exit 2
36         fi
37 }
38
39 if [ $# -lt 1 ]
40 then
41         usage
42         exit 2
43 fi
44
45 CURRENT_DIR=`pwd`
46 BASEDIR=$(dirname $0)
47
48 if [ ${BASEDIR:0:1} = "/" ]
49 then
50         FULL_PATH=$BASEDIR
51 else
52         FULL_PATH=$CURRENT_DIR/$BASEDIR
53 fi
54
55 LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j.properties
56 #############################################
57 TARGET_DIR=${FULL_PATH}/target
58 CONF_FILE=${FULL_PATH}/conf/attsdc.yaml
59 DEBUG=true
60 #MainClass=org.openecomp.tlv.sdc.ci.tests.run.StartTest
61 MainClass=org.openecomp.test.ClientTest
62
63 JAR_FILE=$1
64
65 #TARGET_DIR=`echo ${TARGET_DIR} | sed 's/\//\//g'`
66 #echo $TARGET_DIR
67
68 TESTS_DIR=/opt/app/sdc/ci/resources/tests
69 COMPONENTS_DIR=/opt/app/sdc/ci/resources/components
70
71 #sed -i 's#\(outputFolder:\).*#\1 '${TARGET_DIR}'#g' $CONF_FILE
72 #sed -i 's#\(resourceConfigDir:\).*#\1 '${TESTS_DIR}'#g' $CONF_FILE
73 #sed -i 's#\(componentsConfigDir:\).*#\1 '${COMPONENTS_DIR}'#g' $CONF_FILE
74 TARGET_LOG_DIR="${TARGET_DIR}/"
75
76 mkdir -p ${TARGET_DIR}
77 if [ -d ${TARGET_DIR} ]
78 then
79     rm -rf ${TARGET_DIR}/*
80         exitOnError $? "Failed_to_delete_target_dir"
81 fi
82
83 debug_port=8800
84 #JAVA_OPTION="-javaagent:/var/tmp/jacoco/lib/jacocoagent.jar=destfile=jacoco-it.exec"
85 JAVA_OPTION=""
86 case "$2" in
87         -debug) echo "Debug mode, Listen on port $debug_port"; JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ;;
88         "") echo "Standard mode";;
89         *) echo "USAGE: startTest.sh [-debug]";;
90 esac
91
92 cmd="java $JAVA_OPTION -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -cp $JAR_FILE ${MainClass}" 
93
94 #echo $cmd
95 #console=`$cmd`
96
97 if [ $DEBUG == "true" ]
98 then
99         $cmd
100 else
101         $cmd >> /dev/null
102 fi 
103 status=`echo $?`
104
105
106
107 echo "##################################################"
108 echo "################# status is ${status} #################" 
109 echo "##################################################"
110
111 exit $status 
112