forked from spring-boot-template/dvl-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·314 lines (251 loc) · 7.68 KB
/
test.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
# depends on https://github.com/ulisseslima/bash-utils.git
mydir=$(dirname `readlink -f $0`)
me=$(readlink -f $0)
app=dvl-app
core=dvl-core
corev='1.0.1'
NAMESPACE='http://maven.apache.org/POM/4.0.0'
if [[ -n "$1" ]]; then
altdir="$(readlink -f $1)"
if [[ ! -d "$altdir/$app" ]]; then
echo "invalid dir: $altdir"
exit 1
fi
mydir="$altdir/$app"
fi
echo && echo "################################"
echo "dir: $mydir"
total_points=0
ok_points=0
ascii_code() {
LC_CTYPE=C printf '%d' "'$1"
}
gprop() {
f="$mydir/src/main/resources/application.properties"
if [[ -f "$f" ]]; then
>&2 echo "analyzing: $f"
grep "$1" $mydir/src/main/resources/application.properties | grep -v '#' | cut -d'=' -f2
else
>&2 echo "not a file: $f"
exit 1
fi
}
linkedin_name=$(gprop 'linkedin.name')
port=$(gprop 'server.port')
name_1=$(ascii_code ${linkedin_name:0:1})
name_port="${name_1}80"
echo && echo "linkedin:"
echo "https://www.linkedin.com/in/${linkedin_name}/"
api_base_url="http://localhost:${port}/${linkedin_name:0:3}"
web_base_url="http://localhost:${port}"
cd $mydir
git pull
if [[ -n "${port}" ]]; then
logs=/tmp/${app}-test.out
pom=pom.xml
dvl_core_v=$(xmlstarlet sel -N x=$NAMESPACE -t -v "x:project/x:dependencies/x:dependency[x:artifactId='$core']/x:version" $pom)
echo "dvl-core version: $dvl_core_v"
if [[ "$dvl_core_v" != "$corev" ]]; then
xmlstarlet ed -L -N x="$NAMESPACE" \
-u "x:project/x:dependencies/x:dependency[x:artifactId='$core']/x:version" -v "$corev" \
$pom
dvl_core_v=$(xmlstarlet sel -N x=$NAMESPACE -t -v "x:project/x:dependencies/x:dependency[x:artifactId='$core']/x:version" $pom)
echo "dvl-core version changed: $dvl_core_v"
fi
nohup ./mvnw spring-boot:run &> $logs&
pid=$!
echo "starting server. pid: $pid, logs: $logs"
while [[ -n "$(assert-up.sh $web_base_url 2>&1)" ]]
do
echo "waiting for $web_base_url ... ctrl+c to break"
tail $logs
sleep 5
done
else
echo "server won't start"
fi
#echo && echo "local server:"
#echo "$web_base_url"
#if [[ -n "$(assert-up.sh $web_base_url 2>&1)" ]]; then
# echo "local server is not running, press any key to ignore, ctrl+c to stop"
# read any
#fi
POST() {
if [[ ! -n "$api_base_url" ]]; then
echo "api_base_url is undefined"
exit 1
fi
endpoint="${1/\//}"
json="$2"
curl -s -X POST -H 'Content-Type: application/json' "$api_base_url/$endpoint" -d "$json" > /dev/null
}
GET() {
if [[ ! -n "$api_base_url" ]]; then
echo "api_base_url is undefined"
exit 1
fi
endpoint="${1/\//}"
json="$2"
curl -s "$api_base_url/$endpoint"
}
result() {
test="$1"
msg="$2"
extra="$3"
echo "##############"
echo "-- ${FUNCNAME[1]}: $msg $extra"
echo "${test}?"
if eval $test; then
echo OK
ok_points=$((ok_points+1))
else
echo FAIL
fi
total_points=$((total_points+1))
echo "/" && echo
}
# criar uma propriedade custom no arquivo application.properties, com o nome linkedin.name e valor igual ao seu nome de usuário
# (da forma como aparece na URL do LinkedIn). Por exemplo:
# considerando a URL de perfil https://www.linkedin.com/in/joaozinho123/, a variável teria o valor de "joaozinho123".
test_0a_LINKEDIN() {
result "[ -n \"$linkedin_name\" ]"
}
# modificar a aplicação para subir na porta HTTP considerando o valor ASCII do primeiro caractere da variável acima,
# concatenado com "80". Por exemplo: utilizando o exemplo acima, a aplicação subiria na porta 10680.
test_0b_PORTA() {
result "[ \"$port\" == \"$name_port\" ]"
}
# modificar a variável de prefixo REST (já existente) para ser igual aos três primeiros caracteres da variável definida no item a).
test_0c_API_PREFIX() {
api_prefix=$(gprop 'dvl.rest.prefix')
result "[[ \"${api_prefix:1}\" == \"${linkedin_name:0:3}\" ]]"
}
# modificar GET /skills para retornar ordenado por nome
test_1_SKILLS_BY_NAME() {
# >&2 echo "posting new objects ..."
POST /skills '{"name": "zzz"}'
POST /skills '{"name": "yyy"}'
POST /skills '{"name": "aaa"}'
response=$(GET '/skills')
first=$(echo "$response" | jprop.sh "[0]['name']")
result "[[ \"$first\" == \"aaa\" ]]"
}
# modificar GET /stats para retornar ordenado por total (decrescente) e avg (decrescente)
test_2_STATS_ORDER() {
#echo "$web_base_url/stats/list.htm"
response=$(GET '/stats')
echo "$response" > /tmp/stats
first=$(echo "$response" | jprop.sh "[0]['total']")
last=$(echo "$response" | jprop.sh "[-1]['total']")
result "[[ \"$last\" -lt \"$first\" ]]"
}
# corrigir GET /skills/like para filtrar por nome
test_3_SKILLS_LIKE() {
like_search=y
response=$(GET "/skills/like?id=$like_search")
like=$(echo "$response" | jprop.sh "[0]['name']")
if [[ ! -n "$like" ]]; then
response=$(GET "/skills/like?name=$like_search")
like=$(echo "$response" | jprop.sh "[0]['name']")
fi
echo "$response" > /tmp/skills.like
result "[ \"$like\" == yyy ]"
}
# mapear para /jobs
# suporte para GET, POST, DELETE
test_4_JOBS() {
points=0
GET_ALL=$(curl -s -I -X GET "$api_base_url/jobs" | head -n 1 |cut -d$' ' -f2)
GET_ONE=$(curl -s -I -X GET "$api_base_url/jobs/1" | head -n 1 |cut -d$' ' -f2)
POST=$(curl -s -I -X POST "$api_base_url/jobs" | head -n 1 |cut -d$' ' -f2)
DEL=$(curl -s -I -X DELETE "$api_base_url/jobs/0" | head -n 1 |cut -d$' ' -f2)
if [ "$GET_ALL" != 404 ]; then
#echo "$GET_ALL != 404"
points=$((points+1))
fi
if [ "$GET_ONE" != 404 ]; then
#echo "$GET_ONE != 404"
points=$((points+1))
fi
if [ "$POST" != 404 ]; then
#echo "$POST != 404"
points=$((points+1))
fi
if [ "$DEL" != 404 ]; then
#echo "$DEL != 404"
points=$((points+1))
fi
>&2 echo "points=$points"
result "[ \$points == 4 ]"
}
# Criar card no index.html para visualização ou inclusão de Jobs
# seguindo o padrão dos outros cards já existentes
test_4_1_JOBS_MENU() {
class=$(find $mydir -name "JobService.java")
annotation=$(grep -c '@MenuItem' "$class")
result "[[ \"$annotation\" -gt 0 ]]"
}
# com página de listagem
# inserção/edição/remoção
# acessível pela página inicial
test_4_2_JOBS_LIST() {
page=$(find $mydir -name "list.htm" | grep -c jobs)
#find $mydir -name "list.htm" | grep jobs | grep -v "/target" | grep -v "/bin"
#echo "$web_base_url/jobs/list.htm"
result "[[ \"$page\" -gt 0 ]]"
}
# card de jobs aparecendo no index
test_4_3_JOBS_CONSTRAINT() {
class=$(find $mydir -name "JobBean.java")
annotation=$(grep -c '@Table(uniqueConstraints = { @UniqueConstraint(columnNames = "name") })' "$class")
result "[[ \"$annotation\" -gt 0 ]]"
}
# Corrigir a classe RestAspect
test_5_ASPECT() {
class=$(find $mydir -name "RestAspect.java")
annotation=$(grep -c '@Aspect' "$class")
result "[[ \"$annotation\" -gt 0 ]]"
}
# skill com o nome
test_6_SKILL_BY_NAME() {
name=aaa
exists_a=$(GET "/skills/name/$name" | jprop.sh "['name']")
exists_b=$(GET "/skills?name=$name" | jprop.sh "['name']")
if [[ "$exists_a" != $name ]]; then
exists_a=false
fi
if [[ "$exists_b" != $name ]]; then
exists_b=false
fi
result "[[ \"$exists_a\" == $name || \"$exists_b\" == $name ]]"
}
# boolean indicando se bean existe com o nome
test_6_1_SKILL_EXISTS() {
name=aaa
exists_a=$(GET "/skills/exists/name/$name")
exists_b=$(GET "/skills/exists?name=$name")
if [[ "$exists_a" != true ]]; then
exists_a=false
fi
if [[ "$exists_b" != true ]]; then
exists_b=false
fi
result "[[ \"$exists_a\" == true || \"$exists_b\" == true ]]"
}
echo && echo "calling test functions..."
while read func
do
$func
done < <(grep test_ "$me" | grep -v 'done' | cut -d'(' -f1)
min=$((total_points/2+1))
result=FAILED
[[ $ok_points -eq $min ]] && result=LOW
[[ $ok_points -gt $min ]] && result=PASSED
[[ $ok_points -eq $total_points ]] && result=PERFECT
echo && echo "${result}: $ok_points/$total_points"
if [[ -n "$pid" ]]; then
echo "press any key to terminate $web_base_url"
read anyKey
kill $pid
fi