sergehuber commented on code in PR #766:
URL: https://github.com/apache/unomi/pull/766#discussion_r3386779306


##########
itests/src/test/java/org/apache/unomi/itests/SchedulerIT.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.itests;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.util.EntityUtils;
+import org.apache.unomi.api.PartialList;
+import org.apache.unomi.api.services.SchedulerService;
+import org.apache.unomi.api.tasks.ScheduledTask;
+import org.apache.unomi.api.tasks.TaskExecutor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.ops4j.pax.exam.util.Filter;
+
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.*;
+
+/**
+ * Integration tests for the Scheduler REST API
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class SchedulerIT extends BaseIT {
+
+    private final static String TEST_TASK_TYPE = "test-task";
+    private String testTaskId;
+
+    @Before
+    public void setUp() {
+        // Register a test task executor
+        TestTaskExecutor executor = new TestTaskExecutor();
+        schedulerService.registerTaskExecutor(executor);
+
+        // Create a test task
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("testParam", "testValue");
+
+        ScheduledTask task = schedulerService.createTask(
+            TEST_TASK_TYPE,
+            parameters,
+            0,
+            1000,
+            TimeUnit.MILLISECONDS,
+            true,
+            false,
+            false,
+            true
+        );
+        testTaskId = task.getItemId();
+        schedulerService.scheduleTask(task);
+    }
+
+    @After
+    public void tearDown() {
+        // Clean up test task
+        if (testTaskId != null) {
+            try {
+                schedulerService.cancelTask(testTaskId);
+            } catch (Exception e) {
+                // Ignore cleanup errors
+            }
+        }
+    }
+
+    @Test
+    public void testGetTasks() throws Exception {
+        // Test getting all tasks
+        PartialList<ScheduledTask> tasks = get("/cxs/tasks", 
PartialList.class);
+        assertNotNull("Tasks list should not be null", tasks);
+        assertTrue("Should have at least one task", tasks.getList().size() > 
0);
+
+        // Test filtering by status
+        tasks = get("/cxs/tasks?status=SCHEDULED", PartialList.class);
+        assertNotNull("Filtered tasks list should not be null", tasks);
+
+        // Test filtering by type
+        tasks = get("/cxs/tasks?type=" + TEST_TASK_TYPE, PartialList.class);
+        assertNotNull("Type-filtered tasks list should not be null", tasks);
+        assertTrue("Should find test task", tasks.getList().size() > 0);
+    }
+
+    @Test
+    public void testGetTask() throws Exception {
+        ScheduledTask task = get("/cxs/tasks/" + testTaskId, 
ScheduledTask.class);
+        assertNotNull("Task should not be null", task);
+        assertEquals("Task ID should match", testTaskId, task.getItemId());
+        assertEquals("Task type should match", TEST_TASK_TYPE, 
task.getTaskType());
+    }
+
+    @Test
+    public void testGetNonExistentTask() throws Exception {
+        ScheduledTask task = get("/cxs/tasks/non-existent-task", 
ScheduledTask.class);
+        assertNull("Task should be null", task);
+    }
+
+    @Test
+    public void testCancelTask() throws Exception {
+        CloseableHttpResponse response = delete("/cxs/tasks/" + testTaskId);
+        assertEquals("Response should be No Content", 204, 
response.getStatusLine().getStatusCode());
+
+        // Verify task is cancelled
+        ScheduledTask task = schedulerService.getTask(testTaskId);
+        assertEquals("Task should be cancelled", 
ScheduledTask.TaskStatus.CANCELLED, task.getStatus());
+    }

Review Comment:
   Fixed. Replaced `delete("/cxs/tasks/" + testTaskId)` with 
`executeHttpRequest(new HttpDelete(getFullUrl(...)))` wrapped in 
try-with-resources, so the response lifecycle is fully controlled by the test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to