diff options
author | 2019-07-12 11:35:54 +0530 | |
---|---|---|
committer | 2019-07-12 14:50:21 +0530 | |
commit | c818065d90aad39e61992ee44fa13568b80ee7b3 (patch) | |
tree | 02126cd73fbdd7c825b7a120a54699fb340ba3ac /src/test/java/org/onap/dcae/TLSTestBase.java | |
parent | 20d8093fd688f0385b7bb9b8e4b09ff60ef23f26 (diff) |
Issue-ID: DCAEGEN2-1661 Fix Some Compilation warnings, sonar issue
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
Change-Id: Id01028b87c101ff2544d93c68a59f9cc46020d8d
Diffstat (limited to 'src/test/java/org/onap/dcae/TLSTestBase.java')
-rw-r--r-- | src/test/java/org/onap/dcae/TLSTestBase.java | 154 |
1 files changed, 0 insertions, 154 deletions
diff --git a/src/test/java/org/onap/dcae/TLSTestBase.java b/src/test/java/org/onap/dcae/TLSTestBase.java deleted file mode 100644 index a35f009..0000000 --- a/src/test/java/org/onap/dcae/TLSTestBase.java +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.onap.dcaegen2.restconfcollector - * ================================================================================ - * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * Copyright (C) 2018-2019 Huawei. 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.dcae; - -import org.json.JSONObject; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.support.BasicAuthenticationInterceptor; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.web.client.RestTemplate; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.LinkedBlockingQueue; - -import static org.onap.dcae.TestingUtilities.*; - -@Configuration -@ExtendWith(SpringExtension.class) -public class TLSTestBase { - protected static final String KEYSTORE_ALIAS = "tomcat"; - protected static final Path RESOURCES = Paths.get("src", "test", "resources"); - protected static final Path KEYSTORE = Paths.get(RESOURCES.toString(), "keystore"); - protected static final Path KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "passwordfile"); - protected static final Path TRUSTSTORE = Paths.get(RESOURCES.toString(), "truststore"); - protected static final Path TRUSTSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "trustpasswordfile"); - protected static final Path RCC_KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "passwordfile"); - protected static final Path RCC_KEYSTORE = Paths.get(RESOURCES.toString(), "keystore"); - - protected static abstract class ConfigurationBase { - protected final ApplicationSettings settings = Mockito.mock(ApplicationSettings.class); - - @Bean - @Primary - public ApplicationSettings settings() { - configureSettings(settings); - return settings; - } - - protected abstract void configureSettings(final ApplicationSettings settings); - } - - @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) - protected abstract class TestClassBase { - @MockBean - @Qualifier("inputQueue") - protected LinkedBlockingQueue<JSONObject> queue; - - @LocalServerPort - private int port; - - private final String keyStorePassword; - private final String trustStorePassword; - - public TestClassBase() { - keyStorePassword = readFile(RCC_KEYSTORE_PASSWORD_FILE); - trustStorePassword = readFile(TRUSTSTORE_PASSWORD_FILE); - } - - private String getURL(final String protocol, final String uri) { - return protocol + "://localhost:" + port + uri; - } - - private RestTemplate addBasicAuth(final RestTemplate template, final String username, final String password) { - template.getInterceptors() - .add(new BasicAuthenticationInterceptor(username, password)); - - return template; - } - - public String createHttpURL(String uri) { - return getURL("http", uri); - } - - public String createHttpsURL(String uri) { - return getURL("https", uri); - } - - public RestTemplate createHttpRestTemplate() { - return new RestTemplate(); - } - - public RestTemplate createHttpsRestTemplate() { - return rethrow(() -> - createRestTemplateWithSsl( - sslBuilderWithTrustStore(KEYSTORE, keyStorePassword).build() - )); - } - - public RestTemplate createHttpsRestTemplateWithKeyStore() { - return rethrow(() -> - createRestTemplateWithSsl( - configureKeyStore( - sslBuilderWithTrustStore(RCC_KEYSTORE, keyStorePassword), - TRUSTSTORE, - trustStorePassword - ).build()) - ); - } - - public ResponseEntity<String> makeHttpRequest() { - return createHttpRestTemplate().getForEntity(createHttpURL("/"), String.class); - } - - public ResponseEntity<String> makeHttpsRequest() { - return createHttpsRestTemplate().getForEntity(createHttpsURL("/"), String.class); - } - - - public ResponseEntity<String> makeHttpsRequestWithBasicAuth(final String username, final String password) { - return addBasicAuth(createHttpsRestTemplate(), username, password) - .getForEntity(createHttpsURL("/"), String.class); - - } - - public ResponseEntity<String> makeHttpsRequestWithClientCert() { - return createHttpsRestTemplateWithKeyStore().getForEntity(createHttpsURL("/"), String.class); - } - - public ResponseEntity<String> makeHttpsRequestWithClientCertAndBasicAuth( - final String username, - final String password) { - return addBasicAuth(createHttpsRestTemplateWithKeyStore(), username, password) - .getForEntity(createHttpsURL("/"), String.class); - } - } -} |