@@ -50,6 +50,14 @@ redeployApp(){
5050}
5151
5252
53+ _check_bug1 (){
54+
55+ addTask ' {"title":"Clear completed task","completed":true}'
56+
57+ clearCompletedTasks
58+
59+ }
60+
5361is_bug1_there (){
5462
5563 kubectl logs -l app=todoapp -c todoapp -n todoapp | grep ' completed=true' > /dev/null
@@ -62,16 +70,18 @@ is_bug1_there(){
6270 printInfo " 🪲 Bug 'Clear completed' is there! Thanks for adding tasks and trying to clear them."
6371 return 0
6472 else
65- printInfo " ⚠️ Please add a couple of task, mark them completed and then click on the 'clear completed' button in order to see if the 🪲 bug is there..."
73+ printWarn " ⚠️ Please add a couple of task, mark them completed and then click on the 'clear completed' button in order to see if the 🪲 bug is there..."
6674 return 1
6775 fi
6876
6977}
7078
79+
7180is_bug1_solved (){
72- addCompletedTask
7381
74- clearCompletedTasks
82+ printInfoSection " Verifying if the 🪲 Bug 'Clear completed' is gone"
83+
84+ _check_bug1
7585
7686 kubectl logs -l app=todoapp -c todoapp -n todoapp | grep ' Removed Todo record.*completed=true' > /dev/null
7787 found_removed=$?
@@ -80,32 +90,145 @@ is_bug1_solved(){
8090 printInfo " ✅ Bug clear completed is gone."
8191 return 0
8292 else
83- printInfo " ⚠️ Bug clear completed is still there, tip: check the Arrays"
93+ printWarn " ⚠️ Bug clear completed is still there, tip: check the Arrays"
8494 return 1
8595 fi
8696
8797}
8898
99+ is_bug2_solved (){
100+ printInfoSection " Verifying if the 🪲 Bug 'Special Characters' is gone"
101+ RC=0
102+
103+ addTask ' {"title":"Exciting validation!?#","completed":false}'
104+
105+ printInfo " Retrieving todos to verify the title..."
106+
107+ response=$( curl -s -X GET $APPLICATION_URL /todos)
108+
109+ # Check if special characters are preserved
110+ if echo " $response " | grep -q ' "title":"Exciting validation!?#"' ; then
111+ printInfo " ✅ Bug special characters is gone. Title preserved correctly."
112+ RC=0
113+ elif echo " $response " | grep -q ' "title":"Exciting validation"' ; then
114+ printWarn " ⚠️ Bug special characters is still there. Special characters were stripped from the title. Tip: Less is more ;)"
115+ RC=1
116+ fi
117+
118+ # Delete taskId
119+ # deleteTask $response
120+ return $RC
121+ }
122+
123+ is_bug3_solved (){
124+ printInfoSection " Verifying if the 🪲 Bug 'Duplicate Task' is gone"
125+ RC=0
126+
127+ # Generate a random 6-character ID
128+ random_id=$( head /dev/urandom | LC_ALL=C tr -dc ' a-zA-Z0-9' | head -c 6)
129+ title=" Duplicated task with ID $random_id "
130+
131+ addTask ' {"title":"' " $title " ' ","completed":false}'
132+
133+ response=$( curl -s -X GET $APPLICATION_URL /todos)
134+ task_id=$( echo " $response " | grep -o ' "title":"' " $title " ' ","id":"[^"]*"' | grep -o ' "id":"[^"]*"' | cut -d' "' -f4)
135+
136+ if [ -n " $task_id " ]; then
137+ printInfo " Duplicating task with ID: $task_id "
138+ dup_response=$( curl -s -X POST $APPLICATION_URL /todos/dup/$task_id )
139+
140+ if echo " $dup_response " | grep -q ' "status":"ok"' ; then
141+ # Get todos again to verify the duplicate
142+ response=$( curl -s -X GET $APPLICATION_URL /todos)
143+
144+ # Count how many tasks have the correct title
145+ count=$( echo " $response " | grep -o ' "title":"' " $title " ' "' | wc -l)
146+
147+ # Verify original task still exists with the same ID
148+ original_exists=$( echo " $response " | grep -q ' "title":"' " $title " ' ","id":"' " $task_id " ' "' && echo " yes" || echo " no" )
149+
150+ # Check if we have 2 tasks with the correct title and the original still exists
151+ if [ " $count " -eq 2 ] && [ " $original_exists " = " yes" ]; then
152+ printInfo " ✅ Bug duplicate task is gone. Found 2 tasks with correct title '$title ', including original with ID: $task_id "
153+ RC=0
154+ else
155+ printWarn " ⚠️ Bug duplicate task is still there. Expected 2 tasks with title '$title ', found: $count . Tip: Check the setter methods in duplicateTodo."
156+ RC=1
157+ fi
158+ else
159+ printInfo " ❌ Failed to execute duplicate"
160+ RC=1
161+ fi
162+ else
163+ printInfo " ❌ Could not find the task to duplicate"
164+ RC=1
165+ fi
166+
167+ return $RC
168+ }
169+
170+ deleteTask (){
171+ response=" $1 "
172+ # might need it later
173+ task_id=$( echo " $response " | grep -o ' "title":"Exciting validation[^"]*","id":"[^"]*"' | grep -o ' "id":"[^"]*"' | cut -d' "' -f4)
174+ if [ -n " $task_id " ]; then
175+ printInfo " Deleting task ID: $task_id "
176+ delete_response=$( curl -s -X DELETE $APPLICATION_URL /todos/$task_id )
177+ if echo " $delete_response " | grep -q ' "status":"ok"' ; then
178+ printInfo " Task deleted successfully"
179+ else
180+ printInfo " Failed to delete task"
181+ fi
182+ fi
183+ }
184+
89185solve_bug1 (){
90186
91- printInfoSection " Solving the Bug Clear Completed"
187+ printInfoSection " Solving the 🪲 Bug Clear Completed"
188+
189+ _solve_bug " solution/bug1"
190+
191+ printInfo " Now add some tasks, mark them completed and click on 'clear completed'"
192+ printInfo " You can assert that the bug is gone also by typing 'is_bug1_solved'"
193+ }
194+
195+ solve_bug2 (){
196+
197+ printInfoSection " Solving the 🪲 Bug Special Characters"
198+ _solve_bug " solution/bug2"
199+
200+ printInfo " Now add some tasks with special characters and see if they are added correctly"
201+ printInfo " You can assert that the bug is gone also by typing 'is_bug2_solved'"
202+ }
203+
204+ solve_bug3 (){
205+
206+ printInfoSection " Solving the 🪲 Bug Duplicated Task"
207+ _solve_bug " solution/bug3"
208+
209+ printInfo " Now duplicate a record and see if the duplicate is correct"
210+ printInfo " You can assert that the bug is gone also by typing 'is_bug3_solved'"
211+ }
212+
213+ _solve_bug (){
214+
215+ solution_branch=$1
92216
93- printInfo " we change to the branch solution/bug1 where the developer already added the solution for us"
217+ printInfo " Changing to the branch $solution_branch where the developer already added the solution for us"
94218
95- printInfo " git checkout solution/bug1 "
219+ printInfo " git checkout $solution_branch "
96220
97- git checkout solution/bug1
221+ git checkout $solution_branch
98222
99223 printInfo " then we compile the application and redeploy it to the Kubernetes Cluster using the function 'redeployApp'"
100224
101225 redeployApp
102226
103- setVersionControl " solution/bug1 "
227+ setVersionControl " $solution_branch "
104228
105- printInfo " Now add some tasks, mark them completed and click on 'clear completed'"
106- printInfo " You can assert that the bug is gone also by typing 'is_bug1_solved'"
107229}
108230
231+
109232setVersionControl (){
110233 printInfo " Setting version control in the DEPLOYMENT_NAME=$DEPLOYMENT_NAME to point to '$1 ' "
111234 updateVersionControl " $1 "
@@ -161,13 +284,14 @@ EOF
161284}
162285
163286
164-
165- # Testing Methods
166-
167- addCompletedTask (){
168- printInfo " adding completed Task"
287+ addTask (){
288+ jsontask=" $1 "
289+ if [ -z " $jsontask " ]; then
290+ jsontask=' {"title":"Completed task","completed":true}'
291+ fi
292+ printInfo " adding task $jsontask "
169293 response=$( curl -s -X POST $APPLICATION_URL /todos \
170- -H " Content-Type: application/json" -d ' {"title":"Completed task","completed":true} ' )
294+ -H " Content-Type: application/json" -d " $jsontask " )
171295
172296 if echo " $response " | grep -q ' "status":"ok"' ; then
173297 printInfo " ✅ Task added successfully"
@@ -186,4 +310,73 @@ clearCompletedTasks(){
186310 printInfo " ❌ Failed to execute Clear completed"
187311 fi
188312
313+ }
314+
315+
316+
317+ assertBugsAndRedeployment (){
318+ printInfoSection " Verifying if the Bug 1 is there..."
319+
320+ _check_bug1
321+
322+ if is_bug1_solved; then
323+ exit 1
324+ fi
325+
326+ printInfo " Bugs are there! now solving 1, 2 and 3 with the TodoController from solution/bug3"
327+
328+ replaceTodoController " solution/bug3"
329+
330+ redeployApp
331+
332+ waitAppCanHandleRequests
333+
334+ if ! is_bug1_solved; then
335+ exit 1
336+ fi
337+
338+ if ! is_bug2_solved; then
339+ exit 1
340+ fi
341+
342+ if ! is_bug3_solved; then
343+ exit 1
344+ fi
345+
346+ }
347+
348+ replaceTodoController (){
349+
350+ solution_branch=" $1 "
351+
352+ printInfoSection " Replacing the TodoController from branch $solution_branch "
353+
354+ if [ -z " $solution_branch " ]; then
355+ printError " No solution branch specified"
356+ return 1
357+ fi
358+
359+ printInfo " Downloading TodoController.java from $solution_branch branch"
360+
361+ curl -s -o app/src/main/java/com/dynatrace/todoapp/TodoController.java \
362+ " https://raw.githubusercontent.com/dynatrace-wwse/enablement-live-debugger-bug-hunting/refs/heads/$solution_branch /app/src/main/java/com/dynatrace/todoapp/TodoController.java"
363+
364+ if [ $? -eq 0 ]; then
365+ printInfo " ✅ TodoController.java downloaded successfully from $solution_branch "
366+ else
367+ printError " ❌ Failed to download TodoController.java from $solution_branch "
368+ return 1
369+ fi
370+
371+ }
372+
373+ assertBug2isThere (){
374+ printInfoSection " Verifying if the Bug 2 is there..."
375+
376+ is_bug2_solved
377+
378+ if ! is_bug1_solved; then
379+ exit 1
380+ fi
381+
189382}
0 commit comments