diff options
Diffstat (limited to 'aai-schema-service/src/test/java')
2 files changed, 74 insertions, 12 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 53a3e14..231fecc 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 @@ -47,6 +47,7 @@ import static org.junit.Assert.assertThat; @TestPropertySource(locations = "classpath:application-test.properties") @ContextConfiguration(initializers = PropertyPasswordConfiguration.class) @Import(SchemaServiceTestConfiguration.class) + @RunWith(SpringRunner.class) public class SchemaServiceTest { @@ -86,7 +87,7 @@ public class SchemaServiceTest { headers.add("X-TransactionId", "JUNIT"); headers.add("Authorization", "Basic " + authorization); httpEntity = new HttpEntity(headers); - baseUrl = "https://localhost:" + randomPort; + baseUrl = "http://localhost:" + randomPort; } @Test @@ -126,6 +127,59 @@ public class SchemaServiceTest { } @Test + public void testInvalidSchemaAndEdges(){ + + headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); + headers.setContentType(MediaType.APPLICATION_XML); + headers.add("Real-Time", "true"); + headers.add("X-FromAppId", "JUNIT"); + headers.add("X-TransactionId", "JUNIT"); + headers.add("Authorization", "Basic " + authorization); + httpEntity = new HttpEntity(headers); + + ResponseEntity responseEntity; + + 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 + ); + + assertThat(responseEntity.getStatusCodeValue(), is(400)); + } + + @Test + public void testVersions(){ + + ResponseEntity responseEntity; + + responseEntity = restTemplate.exchange( + baseUrl + "/aai/schema-service/v1/versions", + HttpMethod.GET, + httpEntity, + String.class + ); + assertThat(responseEntity.getStatusCodeValue(), is(200)); + + + } + + @Test public void testGetStoredQueriesSuccess(){ ResponseEntity responseEntity; 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 5d4c187..1e2de5e 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 @@ -58,30 +58,38 @@ public class SchemaServiceTestConfiguration { @Bean RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception { - 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(); + RestTemplate restTemplate = null; - if(env.acceptsProfiles("two-way-ssl")){ - sslContextBuilder = sslContextBuilder.loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword); - } + 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); + } - SSLContext sslContext = sslContextBuilder + SSLContext sslContext = sslContextBuilder .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword) .build(); - HttpClient client = HttpClients.custom() + HttpClient client = HttpClients.custom() .setSSLContext(sslContext) .setSSLHostnameVerifier((s, sslSession) -> true) .build(); - RestTemplate restTemplate = builder + restTemplate = builder .requestFactory(new HttpComponentsClientHttpRequestFactory(client)) .build(); + }else { + restTemplate = builder.build(); + } + restTemplate.setErrorHandler(new ResponseErrorHandler() { @Override |