dmaap-adaptor 97/7997/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 28 Mar 2022 13:32:01 +0000 (15:32 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 28 Mar 2022 13:32:01 +0000 (15:32 +0200)
Removed code smells.
Improved coverage

Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-735
Change-Id: I391df1746af764c9e188f2269d7855758b36750c

config/keystore.jks
config/truststore.jks
src/main/java/org/oran/dmaapadapter/clients/AsyncRestClientFactory.java
src/test/java/org/oran/dmaapadapter/ApplicationTest.java
src/test/java/org/oran/dmaapadapter/IntegrationWithIcs.java
src/test/java/org/oran/dmaapadapter/IntegrationWithKafka.java

index 122997a..675785b 100644 (file)
Binary files a/config/keystore.jks and b/config/keystore.jks differ
index 60d6288..e883cd6 100644 (file)
Binary files a/config/truststore.jks and b/config/truststore.jks differ
index 18e5900..a1ef1ac 100644 (file)
@@ -82,8 +82,7 @@ public class AsyncRestClientFactory {
                 return new AsyncRestClient(baseUrl, this.sslContextFactory.createSslContext(),
                         useHttpProxy ? httpProxyConfig : null);
             } catch (Exception e) {
-                String exceptionString = e.toString();
-                logger.error("Could not init SSL context, reason: {}", exceptionString);
+                logger.error("Could not init SSL context, reason: {}", e.toString());
             }
         }
         return new AsyncRestClient(baseUrl, null, httpProxyConfig);
index 6660175..24603ec 100644 (file)
@@ -77,6 +77,7 @@ import reactor.test.StepVerifier;
 @TestPropertySource(properties = { //
         "server.ssl.key-store=./config/keystore.jks", //
         "app.webclient.trust-store=./config/truststore.jks", //
+        "app.webclient.trust-store-used=true", //
         "app.configuration-filepath=./src/test/resources/test_application_configuration.json"//
 })
 class ApplicationTest {
@@ -269,7 +270,7 @@ class ApplicationTest {
         kafkaConsumer.start(Flux.just("data"));
 
         ConsumerController.TestResults consumer = this.consumerController.testResults;
-        await().untilAsserted(() -> assertThat(consumer.receivedBodies.size()).isEqualTo(1));
+        await().untilAsserted(() -> assertThat(consumer.receivedBodies).hasSize(1));
         assertThat(consumer.receivedBodies.get(0)).isEqualTo("[\"data\"]");
 
         // Test send an exception
@@ -304,7 +305,7 @@ class ApplicationTest {
         DmaapSimulatorController.dmaapResponses.add("DmaapResponse1");
         DmaapSimulatorController.dmaapResponses.add("DmaapResponse2");
         ConsumerController.TestResults consumer = this.consumerController.testResults;
-        await().untilAsserted(() -> assertThat(consumer.receivedBodies.size()).isEqualTo(2));
+        await().untilAsserted(() -> assertThat(consumer.receivedBodies).hasSize(2));
         assertThat(consumer.receivedBodies.get(0)).isEqualTo("DmaapResponse1");
 
         String jobUrl = baseUrl() + ProducerCallbacksController.JOB_URL;
index 9f0ef19..559b144 100644 (file)
@@ -38,7 +38,6 @@ import org.oran.dmaapadapter.configuration.ImmutableWebClientConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig.HttpProxyConfig;
 import org.oran.dmaapadapter.r1.ConsumerJobInfo;
-import org.oran.dmaapadapter.repository.InfoTypes;
 import org.oran.dmaapadapter.repository.Job;
 import org.oran.dmaapadapter.repository.Jobs;
 import org.oran.dmaapadapter.tasks.ProducerRegstrationTask;
@@ -53,7 +52,6 @@ import org.springframework.http.HttpStatus;
 import org.springframework.test.context.TestPropertySource;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
-
 @SuppressWarnings("java:S3577") // Rename class
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@@ -77,9 +75,6 @@ class IntegrationWithIcs {
     @Autowired
     private Jobs jobs;
 
-    @Autowired
-    private InfoTypes types;
-
     @Autowired
     private ConsumerController consumerController;
 
@@ -262,7 +257,7 @@ class IntegrationWithIcs {
         DmaapSimulatorController.dmaapResponses.add("Junk");
 
         ConsumerController.TestResults results = this.consumerController.testResults;
-        await().untilAsserted(() -> assertThat(results.receivedBodies.size()).isEqualTo(2));
+        await().untilAsserted(() -> assertThat(results.receivedBodies).hasSize(2));
         assertThat(results.receivedBodies.get(0)).isEqualTo("DmaapResponse1");
 
         deleteInformationJobInIcs(DMAAP_JOB_ID);
index 5a48d61..f637917 100644 (file)
@@ -242,12 +242,17 @@ class IntegrationWithKafka {
 
     private void verifiedReceivedByConsumer(String... strings) {
         ConsumerController.TestResults consumer = this.consumerController.testResults;
-        await().untilAsserted(() -> assertThat(consumer.receivedBodies.size()).isEqualTo(strings.length));
+        await().untilAsserted(() -> assertThat(consumer.receivedBodies).hasSize(strings.length));
         for (String s : strings) {
             assertTrue(consumer.hasReceived(s));
         }
     }
 
+    @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests.
+    private static void sleep(long millis) throws InterruptedException {
+        Thread.sleep(millis);
+    }
+
     @Test
     void simpleCase() throws InterruptedException {
         final String JOB_ID = "ID";
@@ -259,7 +264,7 @@ class IntegrationWithKafka {
         this.icsSimulatorController.addJob(consumerJobInfo(null, Duration.ZERO, 0, 1), JOB_ID, restClient());
         await().untilAsserted(() -> assertThat(this.jobs.size()).isEqualTo(1));
 
-        Thread.sleep(4000);
+        sleep(4000);
         var dataToSend = Flux.just(senderRecord("Message"));
         sendDataToStream(dataToSend);
 
@@ -287,7 +292,7 @@ class IntegrationWithKafka {
 
         await().untilAsserted(() -> assertThat(this.jobs.size()).isEqualTo(2));
 
-        Thread.sleep(2000);
+        sleep(2000);
         var dataToSend = Flux.range(1, 3).map(i -> senderRecord("Message_" + i)); // Message_1, Message_2 etc.
         sendDataToStream(dataToSend);
 
@@ -326,7 +331,7 @@ class IntegrationWithKafka {
 
         this.icsSimulatorController.deleteJob(JOB_ID2, restClient()); // Delete one job
         kafkaTopicConsumers.restartNonRunningTopics();
-        Thread.sleep(1000); // Restarting the input seems to take some asynch time
+        sleep(1000); // Restarting the input seems to take some asynch time
 
         dataToSend = Flux.just(senderRecord("Howdy\""));
         sendDataToStream(dataToSend);