Fixing Sonar issues & Test classes added 67/70567/2
authorpwielebs <piotr.wielebski@nokia.com>
Tue, 16 Oct 2018 13:17:51 +0000 (15:17 +0200)
committerpwielebs <piotr.wielebski@nokia.com>
Thu, 18 Oct 2018 10:06:43 +0000 (12:06 +0200)
Change-Id: I88ace2333d9f52fcd81eb4d1b883a04dd329c4cc
Issue-ID: DCAEGEN2-835
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/io/IOutputStream.java
datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/IFileSystemResource.java
datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/IRestTemplate.java
datafile-dmaap-client/src/main/java/org/onap/dcaegen2/collectors/datafile/web/IRestTemplate.java
datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java [new file with mode: 0644]
datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java [new file with mode: 0644]
datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java [new file with mode: 0644]

index cb9d857..1ef790c 100644 (file)
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.OutputStream;
 
+@FunctionalInterface
 public interface IOutputStream {
     public OutputStream getOutputStream(File file) throws FileNotFoundException;
 }
index 7f8d3b5..98e6ab4 100644 (file)
@@ -26,6 +26,7 @@ import org.springframework.http.ResponseEntity;
  * @author
  *
  */
+@FunctionalInterface
 public interface IRestTemplate {
     public ResponseEntity<String> exchange(URI url, HttpMethod method, HttpEntity<byte[]> requestEntity,
             Class<String> responseType);
index 1102b54..e700633 100644 (file)
@@ -26,6 +26,7 @@ import org.springframework.http.ResponseEntity;
  * @author
  *
  */
+@FunctionalInterface
 public interface IRestTemplate {
     public ResponseEntity<String> exchange(URI url, HttpMethod method, HttpEntity<byte[]> requestEntity,
             Class<String> responseType);
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
new file mode 100644 (file)
index 0000000..fb0cc29
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. All rights reserved.
+ * ===============================================================================================
+ * Licensed 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.
+ * ============LICENSE_END========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.web;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class PublishRedirectStrategyTest {
+
+    private static PublishRedirectStrategy publishRedirectStrategy;
+
+
+    @BeforeAll
+    static void setUp() {
+        publishRedirectStrategy = new PublishRedirectStrategy();
+    }
+
+    @Test
+    void isRedirectable_shouldReturnTrue() {
+        Assertions.assertTrue(publishRedirectStrategy.isRedirectable("Put"));
+    }
+
+    @Test
+    void isRedirectable_shouldReturnFalse() {
+        Assertions.assertFalse(publishRedirectStrategy.isRedirectable("not valid method"));
+    }
+}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RequestResponseLoggingInterceptorTest.java
new file mode 100644 (file)
index 0000000..b0f5c93
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
+ * ===============================================================================================
+ * Licensed 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.
+ * ============LICENSE_END========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.web;
+
+
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpRequest;
+import org.springframework.http.client.ClientHttpRequestExecution;
+import org.springframework.http.client.ClientHttpResponse;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+class RequestResponseLoggingInterceptorTest {
+
+    @Test
+    void intercept_shouldReturnObject() throws URISyntaxException, IOException {
+
+        //given
+        RequestResponseLoggingInterceptor requestResponseLoggingInterceptor = new RequestResponseLoggingInterceptor();
+
+        ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
+        HttpRequest request = mock(HttpRequest.class);
+        ClientHttpResponse response = mock(ClientHttpResponse.class);
+
+        byte[] BODY = new byte[] { (byte)0xe0, 0x4f, (byte)0xd0, 0x20, (byte)0xa2 };
+        URI uri = new URI("www.someuri.com");
+
+        //when
+        when(execution.execute(request, BODY)).thenReturn(response);
+
+        //then
+        assertNotNull(requestResponseLoggingInterceptor.intercept(request, BODY, execution));
+    }
+}
diff --git a/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java b/datafile-dmaap-client/src/test/java/org/onap/dcaegen2/collectors/datafile/web/RestTemplateWrapperTest.java
new file mode 100644 (file)
index 0000000..3a0701f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START======================================================================
+ * Copyright (C) 2018 Nordix Foundation. All rights reserved.
+ * ===============================================================================================
+ * Licensed 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.
+ * ============LICENSE_END========================================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.web;
+
+import org.junit.jupiter.api.Test;
+
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class RestTemplateWrapperTest {
+
+    @Test
+    void constructor_shouldReturnNotNullObject() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
+        RestTemplateWrapper restTemplateWrapper = new RestTemplateWrapper();
+        assertNotNull(restTemplateWrapper);
+    }
+}