diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-09-19 16:55:36 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-09-19 16:55:36 +0200 |
commit | 7343beeaf260747aef6a6b9c22acd91de67c5ca0 (patch) | |
tree | cc90d98dfb61d5066184b346612bb04caaae64b4 /aai-schema-service/src/test/java/org | |
parent | e0ad4f2890f9f933199bc6f1b3f0e988da471aa9 (diff) |
Add instructions to invoke the linter and code formatter plugins to the README and invoke the formatter
Issue-ID: AAI-3526
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: Ibd383994732cea6460153704a1153beb530dc6c3
Diffstat (limited to 'aai-schema-service/src/test/java/org')
2 files changed, 59 insertions, 79 deletions
diff --git a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java index 9c214bd..c874038 100644 --- a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java +++ b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTest.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,8 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.UnsupportedEncodingException; +import java.util.Base64; +import java.util.Collections; + import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -36,14 +44,9 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; -import java.io.UnsupportedEncodingException; -import java.util.Base64; -import java.util.Collections; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SchemaServiceApp.class) +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = SchemaServiceApp.class) @TestPropertySource(locations = "classpath:application-test.properties") @ContextConfiguration(initializers = PropertyPasswordConfiguration.class) @Import(SchemaServiceTestConfiguration.class) @@ -91,7 +94,7 @@ public class SchemaServiceTest { } @Test - public void testGetSchemaAndEdgeRules(){ + public void testGetSchemaAndEdgeRules() { headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); @@ -104,30 +107,23 @@ public class SchemaServiceTest { ResponseEntity responseEntity; - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/nodes?version=v20", - HttpMethod.GET, - httpEntity, - String.class - ); + responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=v20", + HttpMethod.GET, httpEntity, String.class); assertThat(responseEntity.getStatusCodeValue(), is(200)); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); httpEntity = new HttpEntity(headers); - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/edgerules?version=v20", - HttpMethod.GET, - httpEntity, - String.class - ); + responseEntity = + restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=v20", + HttpMethod.GET, httpEntity, String.class); assertThat(responseEntity.getStatusCodeValue(), is(200)); } @Test - public void testInvalidSchemaAndEdges(){ + public void testInvalidSchemaAndEdges() { headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); @@ -140,56 +136,41 @@ public class SchemaServiceTest { ResponseEntity responseEntity; - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/nodes?version=blah", - HttpMethod.GET, - httpEntity, - String.class - ); - System.out.println(" "+responseEntity.getBody()); + responseEntity = + restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=blah", + HttpMethod.GET, httpEntity, String.class); + System.out.println(" " + responseEntity.getBody()); assertThat(responseEntity.getStatusCodeValue(), is(400)); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); httpEntity = new HttpEntity(headers); - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/edgerules?version=blah", - HttpMethod.GET, - httpEntity, - String.class - ); + responseEntity = + restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=blah", + HttpMethod.GET, httpEntity, String.class); assertThat(responseEntity.getStatusCodeValue(), is(400)); } @Test - public void testVersions(){ + public void testVersions() { ResponseEntity responseEntity; - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/versions", - HttpMethod.GET, - httpEntity, - String.class - ); + responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/versions", + HttpMethod.GET, httpEntity, String.class); assertThat(responseEntity.getStatusCodeValue(), is(200)); - } @Test - public void testGetStoredQueriesSuccess(){ + public void testGetStoredQueriesSuccess() { ResponseEntity responseEntity; - responseEntity = restTemplate.exchange( - baseUrl + "/aai/schema-service/v1/stored-queries", - HttpMethod.GET, - httpEntity, - String.class - ); + responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/stored-queries", + HttpMethod.GET, httpEntity, String.class); assertThat(responseEntity.getStatusCodeValue(), is(200)); } diff --git a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTestConfiguration.java b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTestConfiguration.java index ba8ae26..938d509 100644 --- a/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTestConfiguration.java +++ b/aai-schema-service/src/test/java/org/onap/aai/schemaservice/SchemaServiceTestConfiguration.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,13 +17,22 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; + +import javax.net.ssl.SSLContext; + import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -36,17 +45,11 @@ import org.springframework.util.ResourceUtils; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; -import javax.net.ssl.SSLContext; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; - @TestConfiguration public class SchemaServiceTestConfiguration { - private static final Logger logger = LoggerFactory.getLogger(SchemaServiceTestConfiguration.class); + private static final Logger logger = + LoggerFactory.getLogger(SchemaServiceTestConfiguration.class); @Autowired private Environment env; @@ -58,39 +61,35 @@ public class SchemaServiceTestConfiguration { @Bean RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception { - - RestTemplate restTemplate = null; - if(env.acceptsProfiles("one-way-ssl", "two-way-ssl")) { - char[] trustStorePassword = env.getProperty("server.ssl.trust-store-password").toCharArray(); - char[] keyStorePassword = env.getProperty("server.ssl.key-store-password").toCharArray(); + if (env.acceptsProfiles("one-way-ssl", "two-way-ssl")) { + char[] trustStorePassword = + env.getProperty("server.ssl.trust-store-password").toCharArray(); + char[] keyStorePassword = + env.getProperty("server.ssl.key-store-password").toCharArray(); String keyStore = env.getProperty("server.ssl.key-store"); String trustStore = env.getProperty("server.ssl.trust-store"); SSLContextBuilder sslContextBuilder = SSLContextBuilder.create(); if (env.acceptsProfiles("two-way-ssl")) { - sslContextBuilder = sslContextBuilder.loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); + sslContextBuilder = sslContextBuilder + .loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); } SSLContext sslContext = sslContextBuilder - .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword) - .build(); + .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build(); - HttpClient client = HttpClients.custom() - .setSSLContext(sslContext) - .setSSLHostnameVerifier((s, sslSession) -> true) - .build(); + HttpClient client = HttpClients.custom().setSSLContext(sslContext) + .setSSLHostnameVerifier((s, sslSession) -> true).build(); restTemplate = builder - .requestFactory(() -> new HttpComponentsClientHttpRequestFactory(client)) - .build(); - }else { + .requestFactory(() -> new HttpComponentsClientHttpRequestFactory(client)).build(); + } else { restTemplate = builder.build(); } - restTemplate.setErrorHandler(new ResponseErrorHandler() { @Override public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException { @@ -103,7 +102,7 @@ public class SchemaServiceTestConfiguration { return true; } - if(clientHttpResponse.getRawStatusCode() % 100 == 5){ + if (clientHttpResponse.getRawStatusCode() % 100 == 5) { logger.debug("Call returned a error " + clientHttpResponse.getStatusText()); return true; } |