You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/06/30 14:07:10 UTC

[camel] branch main updated: (chores) camel-openstack tests: cleanups

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new dfa0b16cf55 (chores) camel-openstack tests: cleanups
dfa0b16cf55 is described below

commit dfa0b16cf55e02dd51d63c69e9fb66991885e424
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Jun 30 14:46:07 2022 +0200

    (chores) camel-openstack tests: cleanups
    
    - avoid unnecessary type specification
    - remove NO-OP code
    - fix duplicate map key
    - simplify assertions
    - simplify exception tests
---
 .../openstack/it/OpenstackCinderVolumeTest.java        |  2 +-
 .../openstack/it/OpenstackKeystoneRegionTest.java      |  2 +-
 .../openstack/it/OpenstackNovaServerTest.java          | 18 ++++++++----------
 .../component/openstack/nova/KeypairProducerTest.java  |  7 -------
 4 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackCinderVolumeTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackCinderVolumeTest.java
index 793a5ec1ef2..3dd50ce0670 100644
--- a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackCinderVolumeTest.java
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackCinderVolumeTest.java
@@ -112,7 +112,7 @@ public class OpenstackCinderVolumeTest extends OpenstackWiremockTestSupport {
         headers.put(CinderConstants.VOLUME_ID, "fffab33e-38e8-4626-9fee-fe90f240ff0f");
         headers.put(OpenstackConstants.NAME, "name");
         headers.put(OpenstackConstants.DESCRIPTION, "description");
-        headers.put(CinderConstants.DESCRIPTION, 1024);
+        headers.put(CinderConstants.SIZE, 1024);
         headers.put(CinderConstants.VOLUME_TYPE, "volume-type");
         headers.put(CinderConstants.IMAGE_REF, "image-ref");
         headers.put(CinderConstants.SNAPSHOT_ID, "snaphot-id");
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackKeystoneRegionTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackKeystoneRegionTest.java
index 97545044010..4544ef78e2e 100644
--- a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackKeystoneRegionTest.java
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackKeystoneRegionTest.java
@@ -70,7 +70,7 @@ public class OpenstackKeystoneRegionTest extends OpenstackWiremockTestSupport {
 
         assertEquals(2, regions.length);
         assertEquals(REGION_PARENTREGIONID, regions[0].getId());
-        assertEquals(null, regions[0].getParentRegionId());
+        assertNull(regions[0].getParentRegionId());
         assertEquals(REGION_ID, regions[1].getId());
         assertEquals(REGION_PARENTREGIONID, regions[1].getParentRegionId());
     }
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackNovaServerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackNovaServerTest.java
index 54848fc6680..4a1e584b469 100644
--- a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackNovaServerTest.java
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/it/OpenstackNovaServerTest.java
@@ -30,9 +30,9 @@ import org.openstack4j.model.compute.Server.Status;
 import org.openstack4j.model.compute.ServerCreate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class OpenstackNovaServerTest extends OpenstackWiremockTestSupport {
 
@@ -59,7 +59,7 @@ public class OpenstackNovaServerTest extends OpenstackWiremockTestSupport {
 
     @Test
     void createSnapshotShouldSucceed() {
-        Map<String, Object> headers = new HashMap<String, Object>();
+        Map<String, Object> headers = new HashMap<>();
         headers.put(OpenstackConstants.ID, SERVER_ID);
         headers.put(OpenstackConstants.NAME, SERVER_SNAPSHOT_NAME);
 
@@ -73,13 +73,11 @@ public class OpenstackNovaServerTest extends OpenstackWiremockTestSupport {
     void getWrongIdShouldThrow() {
         String uri = String.format(URI_FORMAT, url(), OpenstackConstants.GET);
 
-        try {
-            template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, SERVER_WRONG_ID, Server.class);
-            fail("Getting nova server with wrong id should throw");
-        } catch (Exception ex) {
-            assertTrue(ex instanceof CamelExecutionException);
-            assertTrue(((CamelExecutionException) ex).getCause() instanceof ServerResponseException);
-        }
+        Exception ex = assertThrows(CamelExecutionException.class,
+                () -> template.requestBodyAndHeader(uri, null, OpenstackConstants.ID, SERVER_WRONG_ID, Server.class),
+                "Getting nova server with wrong id should throw");
+
+        assertInstanceOf(ServerResponseException.class, ex.getCause());
     }
 
     @Test
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/nova/KeypairProducerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/nova/KeypairProducerTest.java
index 8d867ba7962..ae4298b3cad 100644
--- a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/nova/KeypairProducerTest.java
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/nova/KeypairProducerTest.java
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.component.openstack.nova;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.camel.component.openstack.common.OpenstackConstants;
 import org.apache.camel.component.openstack.nova.producer.KeypairProducer;
 import org.junit.jupiter.api.BeforeEach;
@@ -67,10 +64,6 @@ public class KeypairProducerTest extends NovaProducerTestSupport {
         when(keypairService.create(anyString(), anyString())).thenReturn(osTestKeypair);
         when(keypairService.create(anyString(), isNull())).thenReturn(osTestKeypair);
 
-        List<org.openstack4j.model.compute.Keypair> getAllList = new ArrayList<>();
-        getAllList.add(osTestKeypair);
-        getAllList.add(osTestKeypair);
-
         when(osTestKeypair.getName()).thenReturn(dummyKeypair.getName());
         when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
     }