camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [camel-quarkus] aldettinger commented on a change in pull request #2497: Add integration tests #2388
Date Tue, 20 Apr 2021 19:58:33 GMT

aldettinger commented on a change in pull request #2497:
URL: https://github.com/apache/camel-quarkus/pull/2497#discussion_r616992400



##########
File path: integration-tests/digitalocean/src/test/java/org/apache/camel/quarkus/component/digitalocean/it/DigitaloceanDropletTest.java
##########
@@ -0,0 +1,451 @@
+/*
+ * 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.camel.quarkus.component.digitalocean.it;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.apache.camel.quarkus.test.wiremock.MockServer;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@SuppressWarnings("unchecked")
+@QuarkusTest
+@QuarkusTestResource(DigitaloceanTestResource.class)
+public class DigitaloceanDropletTest {
+    static final long timeout = 5;
+    static TimeUnit timeoutUnit = TimeUnit.SECONDS;
+    static boolean waitBlockStorageAction = false;
+
+    @MockServer
+    WireMockServer server;
+
+    @BeforeAll
+    public static void initTimeoutUnit() {
+        // add timeout if not using MockServer
+        // when using a Digitalocean Key, it takes at least 2 minutes to create a droplet
or snapshot
+        String key = System.getenv("DIGITALOCEAN_AUTH_TOKEN");
+        if (key != null) {
+            timeoutUnit = TimeUnit.MINUTES;
+            waitBlockStorageAction = true;
+        }
+    }
+
+    /**
+     * Testing droplet producer and all tests of producers related to an existing droplet
+     *
+     */
+    @Test
+    void testDroplets() throws InterruptedException {
+        // insert multiple droplets
+        Integer dropletId = RestAssured.given().contentType(ContentType.JSON).put("/digitalocean/droplet/droplet1")
+                .then().extract().body().as(Integer.class);
+        assertNotNull(dropletId);
+
+        // get the droplet by dropletId1 until its status is active and ready
+        // it takes time only if using a oAuthToken from Digitalocean
+        waitActiveDroplet(dropletId);
+
+        // test actions on droplet
+        performActions(dropletId);
+
+        // test actions
+        testResultActions(dropletId);
+
+        // test neighbors
+        testNeighbors(dropletId);
+
+        // test floating IP
+        testFloatingIP(dropletId);
+
+        // test images
+        testImages();
+
+        // test snapshots
+        testSnapshots();
+
+        // test block storages
+        testBlockStorages(dropletId);
+
+        // delete the droplet with id droplet 1
+        given()
+                .when()
+                .delete("/digitalocean/droplet/" + dropletId)
+                .then()
+                .statusCode(202);
+    }
+
+    private void performActions(Integer dropletId) {
+        // action : enable backups
+        given()
+                .contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/backups/enable/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId))
+                .body("type", equalTo("ENABLE_BACKUPS"));
+
+        // action : power off, before taking a snapshot
+        given()
+                .contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/off/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+
+        // take a snapshot
+        given()
+                .contentType(ContentType.JSON)
+                .body("snapshot1")
+                .post("/digitalocean/droplet/snapshot/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+
+        waitForSnapshot(dropletId);
+
+        // action : disable backups
+        given()
+                .when()
+                .get("/digitalocean/droplet/backups/disable/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+
+        // action : power on
+        given()
+                .contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/on/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+
+        // Reboot droplet
+        given()
+                .contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/reboot/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+
+        // enable Ipv6
+        given()
+                .contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/ipv6/" + dropletId)
+                .then()
+                .body("resourceId", equalTo(dropletId));
+    }
+
+    /**
+     * Test the result of actions performed
+     *
+     */
+    private void testResultActions(Integer dropletId) {
+        // getting the droplet actions
+        List<Map<String, Object>> actions = RestAssured.given().contentType(ContentType.JSON)
+                .get("/digitalocean/droplet/actions/" + dropletId)
+                .then().extract().body().as(List.class);
+        List<String> types = Arrays.asList("ENABLE_BACKUPS", "DISABLE_BACKUPS", "SNAPSHOT",
"POWER_ON", "POWER_OFF", "REBOOT",
+                "ENABLE_IPV6");
+        assertActions(actions, types);
+
+        // getting the snapshot action id
+        Integer snapshotActionId = getSnapshotActionId(actions);
+
+        // getting one action
+        given()
+                .get("/digitalocean/action/" + snapshotActionId)
+                .then()
+                .body("id", equalTo(snapshotActionId));
+
+        // getting all actions on the account
+        actions = RestAssured.given().contentType(ContentType.JSON)
+                .get("/digitalocean/actions/")
+                .then().extract().body().as(List.class);
+        types = Arrays.asList("ENABLE_BACKUPS", "DISABLE_BACKUPS", "SNAPSHOT", "POWER_ON",
"POWER_OFF", "REBOOT");
+        assertActions(actions, types);
+    }
+
+    /**
+     * Gets the snapshots and waits until the snapshot is created in Digitalocean.
+     *
+     */
+    private void waitForSnapshot(Integer dropletId) {
+        await().atMost(timeout, timeoutUnit).until(() -> {
+            String path = "/digitalocean/droplet/snapshots/" + dropletId;
+            List<Map<String, Object>> result = given().when().get(path).then().extract().as(List.class);
+            // Look for the snapshot
+            Optional<Map<String, Object>> optional = result.stream()
+                    .filter(s -> "snapshot1".equals(s.get("name")))
+                    .findAny();
+            return optional.isPresent();
+        });
+    }
+
+    /**
+     * Gets the droplet and waits until the droplet is Active in Digitalocean.
+     *
+     */
+    private void waitActiveDroplet(Integer dropletId) {
+        await().atMost(timeout, timeoutUnit).until(() -> {
+            String path = "/digitalocean/droplet/" + dropletId;
+            Map<String, Object> droplet = given()
+                    .contentType(ContentType.JSON).get(path).then().extract().as(Map.class);
+            return droplet != null && dropletId.equals(droplet.get("id")) &&
"ACTIVE".equals(droplet.get("status"));
+        });
+    }
+
+    /**
+     * Assert all the actions
+     *
+     */
+    private void assertActions(List<Map<String, Object>> actions, List<String>
types) {
+        // verify there are actions
+        assertNotNull(actions);
+        // verify there are at least the 7 created actions in the test

Review comment:
       So, I guess it's not always 7 in the context of this function.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message