2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.schemaservice;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
28 import org.onap.aai.util.AAIConfig;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.context.embedded.LocalServerPort;
31 import org.springframework.boot.test.context.SpringBootTest;
32 import org.springframework.context.annotation.Import;
33 import org.springframework.http.*;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.TestPropertySource;
36 import org.springframework.test.context.junit4.SpringRunner;
37 import org.springframework.web.client.RestTemplate;
39 import java.io.UnsupportedEncodingException;
40 import java.util.Base64;
41 import java.util.Collections;
43 import static org.hamcrest.Matchers.is;
44 import static org.junit.Assert.assertThat;
46 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SchemaServiceApp.class)
47 @TestPropertySource(locations = "classpath:application-test.properties")
48 @ContextConfiguration(initializers = PropertyPasswordConfiguration.class)
49 @Import(SchemaServiceTestConfiguration.class)
50 @RunWith(SpringRunner.class)
51 public class SchemaServiceTest {
53 private HttpHeaders headers;
55 private HttpEntity httpEntity;
57 private String baseUrl;
60 private RestTemplate restTemplate;
62 private String authorization;
65 protected int randomPort;
68 public static void setupConfig() throws AAIException {
69 System.setProperty("AJSC_HOME", "./");
70 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/");
71 System.out.println("Current directory: " + System.getProperty("user.dir"));
75 public void setup() throws AAIException, UnsupportedEncodingException {
78 headers = new HttpHeaders();
80 authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8"));
82 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
83 headers.setContentType(MediaType.APPLICATION_JSON);
84 headers.add("Real-Time", "true");
85 headers.add("X-FromAppId", "JUNIT");
86 headers.add("X-TransactionId", "JUNIT");
87 headers.add("Authorization", "Basic " + authorization);
88 httpEntity = new HttpEntity(headers);
89 baseUrl = "https://localhost:" + randomPort;
93 public void testGetSchemaAndEdgeRules(){
95 headers = new HttpHeaders();
96 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
97 headers.setContentType(MediaType.APPLICATION_XML);
98 headers.add("Real-Time", "true");
99 headers.add("X-FromAppId", "JUNIT");
100 headers.add("X-TransactionId", "JUNIT");
101 headers.add("Authorization", "Basic " + authorization);
102 httpEntity = new HttpEntity(headers);
104 ResponseEntity responseEntity;
106 responseEntity = restTemplate.exchange(
107 baseUrl + "/aai/schema-service/v1/nodes?version=v15",
112 assertThat(responseEntity.getStatusCodeValue(), is(200));
114 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
115 headers.setContentType(MediaType.APPLICATION_JSON);
116 httpEntity = new HttpEntity(headers);
118 responseEntity = restTemplate.exchange(
119 baseUrl + "/aai/schema-service/v1/edgerules?version=v15",
125 assertThat(responseEntity.getStatusCodeValue(), is(200));
129 public void testGetStoredQueriesSuccess(){
131 ResponseEntity responseEntity;
133 responseEntity = restTemplate.exchange(
134 baseUrl + "/aai/schema-service/v1/stored-queries",
139 assertThat(responseEntity.getStatusCodeValue(), is(200));