-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2_test
More file actions
executable file
·122 lines (104 loc) · 3.23 KB
/
p2_test
File metadata and controls
executable file
·122 lines (104 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
TMP_DIR=/tmp/p2-grading/
REQUIRED_FILES="TEAM.txt deploy.sh build.gradle create.sql edit.png preview.png list.png src/main/webapp/WEB-INF/web.xml"
ZIP_FILE=$1
function error_exit()
{
echo -e "ERROR: $1" 1>&2
rm -rf ${TMP_DIR}
exit 1
}
function check_files()
{
for FILE in $1; do
if [ ! -f ${FILE} ]; then
error_exit "Cannot find ${FILE} in $2"
fi
done
}
# usage
if [ $# -ne 1 ]; then
echo "Usage: $0 project2.zip" 1>&2
exit
fi
if [ `whoami` != "cs144" ]; then
error_exit "You need to run this script within the container"
fi
# clean any existing files
rm -rf ${TMP_DIR}
mkdir ${TMP_DIR}
# unzip the submission zip file
if [ ! -f ${ZIP_FILE} ]; then
error_exit "Cannot find $ZIP_FILE"
fi
unzip -q -d ${TMP_DIR} ${ZIP_FILE}
if [ "$?" -ne "0" ]; then
error_exit "Cannot unzip ${ZIP_FILE} to ${TMP_DIR}"
fi
# change directory to the grading folder
cd ${TMP_DIR}
# check the existence of the required files
check_files "${REQUIRED_FILES}" "the zip file"
# check the existence of any java file
JAVA_FILES=`find src/main/java -name '*.java' -print`
if [ -z "${JAVA_FILES}" ]; then
error_exit "No java file is included in src/main/java folder of ${ZIP_FILE}"
fi
# check the existence of any jsp file
JSP_FILES=`find src/main/webapp -name '*.jsp' -print`
if [ -z "${JSP_FILES}" ]; then
error_exit "No jsp file is included in src/main/webapp folder of ${ZIP_FILE}"
fi
# check the format of TEAM.txt
VALID_UID=$(grep -E "^[0-9]{9}\s*$" TEAM.txt)
if [ -z "${VALID_UID}" ]; then
error_exit "No valid UID was found in TEAM.txt.\nInclude one 9-digit UID per line. No spaces or dashes, please."
fi
NON_UID=$(grep -v -E "^[0-9]{9}\s*$" TEAM.txt)
if [ -n "${NON_UID}" ]; then
error_exit "Following lines are invalid in TEAM.txt\n${NON_UID}\nInclude one 9-digit UID per line. No spaces or dashes, please."
fi
#
# Done with basic checking. Run the submitted code now
#
echo "dropping all tables in CS144 database"
mysql -Nse 'show tables' CS144 | while read table; do mysql CS144 -e "drop table $table"; done
echo "building and deploying your application..."
rm -f $CATALINA_BASE/webapps/editor.war
gradle clean
sh ./deploy.sh
echo "Finished deploying your app. Sleeping for 30 seconds for Tomcat to pick it up..."
sleep 30
#
# Send two test requests to Tomcat and check the response
#
# 1. check 200 response
URL="http://localhost:8080/editor/post?action=open&username=user_XYRSAF&postid=1"
echo
echo
echo "Requesting ${URL}"
echo "This is the response from Tomcat. Make sure that it is what you expect"
curl -s ${URL}
if [ $? -ne 0 ]; then
error_exit "Failed to get response at ${URL}"
fi
response_code=`curl -s -o /dev/null -w "%{http_code}" ${URL}`
if [ $response_code != "200" ]; then
error_exit "HTTP response code from ${URL} is incorrect"
fi
# 2. check 404 response
URL="http://localhost:8080/editor/post?action=open&username=user_XYRSAF&postid=10"
echo
echo
echo "Requesting ${URL}"
echo "This is the response from Tomcat. Make sure that it is what you expect"
curl -s ${URL}
response_code=`curl -s -o /dev/null -w "%{http_code}" ${URL}`
if [ $response_code != "404" ]; then
error_exit "HTTP response code from ${URL} is incorrect"
fi
# clean up
rm -rf ${TMP_DIR}
echo
echo "SUCCESS!" 1>&2
exit 0