Fix Sonar issues 98/6098/3
authorelinuxhenrik <henrik.b.andersson@est.tech>
Wed, 26 May 2021 14:03:46 +0000 (16:03 +0200)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Wed, 26 May 2021 14:07:49 +0000 (16:07 +0200)
Isue-ID: NONRTRIC-518
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: I6150bdcc6e4a30acb6148107b1073d10aae20740

enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eCallbacks.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/a1e/A1eController.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerController.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1producer/ProducerCallbacks.java
enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1producer/ProducerController.java
enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java
enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java
r-app-catalogue/src/test/java/org/oransc/rappcatalogue/HttpsRequestTest.java

index 85927c7..1b8e064 100644 (file)
@@ -207,9 +207,7 @@ public class AsyncRestClient {
             });
 
         if (this.sslContext != null) {
-            httpClient = httpClient.secure(ssl -> {
-                ssl.sslContext(sslContext);
-            });
+            httpClient = httpClient.secure(ssl -> ssl.sslContext(sslContext));
         }
 
         if (isHttpProxyConfigured()) {
index 17f6351..59ac892 100644 (file)
@@ -83,7 +83,5 @@ public class A1eCallbacks {
                 logger.warn("Consumer notify failed {} {}", job.getJobStatusUrl(), throwable.toString());
                 return Mono.empty();
             });
-
     }
-
 }
index 4c5f5d0..5f796b8 100644 (file)
@@ -332,7 +332,7 @@ public class A1eController {
 
                 String schemaAsString = mapper.writeValueAsString(schemaObj);
                 JSONObject schemaJSON = new JSONObject(schemaAsString);
-                org.everit.json.schema.Schema schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
+                var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
 
                 String objectAsString = mapper.writeValueAsString(object);
                 JSONObject json = new JSONObject(objectAsString);
index 94f4684..18897c3 100644 (file)
@@ -344,7 +344,7 @@ public class ConsumerController {
 
                 String schemaAsString = mapper.writeValueAsString(schemaObj);
                 JSONObject schemaJSON = new JSONObject(schemaAsString);
-                org.everit.json.schema.Schema schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
+                var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
 
                 String objectAsString = mapper.writeValueAsString(object);
                 JSONObject json = new JSONObject(objectAsString);
index 61cd519..166c0d5 100644 (file)
@@ -75,7 +75,7 @@ public class ProducerCallbacks {
 
     /**
      * Start a job in all producers that suports the job type
-     * 
+     *
      * @param infoJob an Information Job
      * @return the number of producers that returned OK
      */
@@ -89,7 +89,7 @@ public class ProducerCallbacks {
 
     /**
      * Start all jobs for one producer
-     * 
+     *
      * @param producer
      * @param infoJobs
      */
index 236d32a..8d2fef9 100644 (file)
@@ -230,8 +230,8 @@ public class ProducerController {
     public ResponseEntity<Object> getInfoProducer( //
         @PathVariable("infoProducerId") String infoProducerId) {
         try {
-            InfoProducer p = this.infoProducers.getProducer(infoProducerId);
-            ProducerRegistrationInfo info = toProducerRegistrationInfo(p);
+            InfoProducer  producer = this.infoProducers.getProducer(infoProducerId);
+            ProducerRegistrationInfo info = toProducerRegistrationInfo(producer);
             return new ResponseEntity<>(gson.toJson(info), HttpStatus.OK);
         } catch (Exception e) {
             return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
@@ -299,9 +299,8 @@ public class ProducerController {
     }
 
     private ProducerStatusInfo producerStatusInfo(InfoProducer producer) {
-        ProducerStatusInfo.OperationalState opState =
-            producer.isAvailable() ? ProducerStatusInfo.OperationalState.ENABLED
-                : ProducerStatusInfo.OperationalState.DISABLED;
+        var opState = producer.isAvailable() ? ProducerStatusInfo.OperationalState.ENABLED
+            : ProducerStatusInfo.OperationalState.DISABLED;
         return new ProducerStatusInfo(opState);
     }
 
@@ -405,5 +404,4 @@ public class ProducerController {
             .supportedTypes(supportedTypes) //
             .build();
     }
-
 }
index 5ea62f0..cbc34cb 100644 (file)
@@ -543,7 +543,7 @@ class ApplicationTest {
         putInfoType(TYPE_ID);
         String url = ProducerConsts.API_ROOT + "/info-types/" + TYPE_ID;
         restClient().delete(url).block();
-        assertThat(this.infoTypes.size()).isEqualTo(0);
+        assertThat(this.infoTypes.size()).isZero();
 
         testErrorCode(restClient().delete(url), HttpStatus.NOT_FOUND, "Information type not found");
     }
@@ -598,7 +598,7 @@ class ApplicationTest {
         assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
 
         assertThat(this.infoTypes.size()).isEqualTo(1);
-        assertThat(this.infoProducers.getProducersForType(TYPE_ID).size()).isEqualTo(1);
+        assertThat(this.infoProducers.getProducersForType(TYPE_ID)).hasSize(1);
         assertThat(this.infoProducers.size()).isEqualTo(1);
         assertThat(this.infoProducers.get("infoProducerId").getInfoTypes().iterator().next().getId())
             .isEqualTo(TYPE_ID);
@@ -794,7 +794,7 @@ class ApplicationTest {
 
         // After 3 failed checks, the producer shall be deregisterred
         this.producerSupervision.createTask().blockLast();
-        assertThat(this.infoProducers.size()).isEqualTo(0); // The producer is removed
+        assertThat(this.infoProducers.size()).isZero(); // The producer is removed
         assertThat(this.infoTypes.size()).isEqualTo(1); // The type remains
 
         // Now we have one disabled job, and no producer.
@@ -864,7 +864,7 @@ class ApplicationTest {
             // Restore the jobs, no jobs in database
             InfoJobs jobs = new InfoJobs(this.applicationConfig, this.producerCallbacks);
             jobs.restoreJobsFromDatabase();
-            assertThat(jobs.size()).isEqualTo(0);
+            assertThat(jobs.size()).isZero();
         }
         logger.warn("Test removing a job when the db file is gone");
         this.infoJobs.remove("jobId1", this.infoProducers);
@@ -892,11 +892,11 @@ class ApplicationTest {
             InfoTypes types = new InfoTypes(this.applicationConfig);
             types.clear();
             types.restoreTypesFromDatabase();
-            assertThat(types.size()).isEqualTo(0);
+            assertThat(types.size()).isZero();
         }
         logger.warn("Test removing a job when the db file is gone");
         this.infoTypes.remove(this.infoTypes.getType(TYPE_ID));
-        assertThat(this.infoJobs.size()).isEqualTo(0);
+        assertThat(this.infoJobs.size()).isZero();
     }
 
     private void deleteEiProducer(String infoProducerId) {
index d51007b..7606311 100644 (file)
@@ -36,6 +36,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
     properties = { //
         "server.ssl.key-store=./config/keystore.jks", //
         "app.webclient.trust-store=./config/truststore.jks"})
+@SuppressWarnings("squid:S3577") // Not containing any tests since it is a mock.
 class MockEnrichmentService {
     private static final Logger logger = LoggerFactory.getLogger(ApplicationTest.class);
 
index 3cf2c2e..9b943df 100644 (file)
@@ -69,7 +69,7 @@ public class HttpsRequestTest {
 
     @Test
     public void testSsl() {
-        assertEquals(this.webServerFactory.getSsl().isEnabled(), true);
+        assertEquals(true, this.webServerFactory.getSsl().isEnabled());
     }
 
     @Test