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=========================================================
21 package org.onap.aai.schemaservice;
23 import static org.hamcrest.Matchers.is;
24 import static org.junit.Assert.assertThat;
26 import java.io.UnsupportedEncodingException;
27 import java.util.Base64;
28 import java.util.Collections;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.aai.exceptions.AAIException;
35 import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
36 import org.onap.aai.util.AAIConfig;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.boot.web.server.LocalServerPort;
40 import org.springframework.context.annotation.Import;
41 import org.springframework.http.*;
42 import org.springframework.test.context.ContextConfiguration;
43 import org.springframework.test.context.TestPropertySource;
44 import org.springframework.test.context.junit4.SpringRunner;
45 import org.springframework.web.client.RestTemplate;
48 webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
49 classes = SchemaServiceApp.class)
50 @TestPropertySource(locations = "classpath:application-test.properties")
51 @ContextConfiguration(initializers = PropertyPasswordConfiguration.class)
52 @Import(SchemaServiceTestConfiguration.class)
54 @RunWith(SpringRunner.class)
55 public class SchemaServiceTest {
57 private HttpHeaders headers;
59 private HttpEntity httpEntity;
61 private String baseUrl;
64 private RestTemplate restTemplate;
66 private String authorization;
69 protected int randomPort;
72 public static void setupConfig() throws AAIException {
73 System.setProperty("AJSC_HOME", "./");
74 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/");
75 System.out.println("Current directory: " + System.getProperty("user.dir"));
79 public void setup() throws AAIException, UnsupportedEncodingException {
82 headers = new HttpHeaders();
84 authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8"));
86 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
87 headers.setContentType(MediaType.APPLICATION_JSON);
88 headers.add("Real-Time", "true");
89 headers.add("X-FromAppId", "JUNIT");
90 headers.add("X-TransactionId", "JUNIT");
91 headers.add("Authorization", "Basic " + authorization);
92 httpEntity = new HttpEntity(headers);
93 baseUrl = "http://localhost:" + randomPort;
97 public void testGetSchemaAndEdgeRules() {
99 headers = new HttpHeaders();
100 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
101 headers.setContentType(MediaType.APPLICATION_XML);
102 headers.add("Real-Time", "true");
103 headers.add("X-FromAppId", "JUNIT");
104 headers.add("X-TransactionId", "JUNIT");
105 headers.add("Authorization", "Basic " + authorization);
106 httpEntity = new HttpEntity(headers);
108 ResponseEntity responseEntity;
110 responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=v20",
111 HttpMethod.GET, httpEntity, String.class);
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);
119 restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=v20",
120 HttpMethod.GET, httpEntity, String.class);
122 assertThat(responseEntity.getStatusCodeValue(), is(200));
126 public void testInvalidSchemaAndEdges() {
128 headers = new HttpHeaders();
129 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
130 headers.setContentType(MediaType.APPLICATION_XML);
131 headers.add("Real-Time", "true");
132 headers.add("X-FromAppId", "JUNIT");
133 headers.add("X-TransactionId", "JUNIT");
134 headers.add("Authorization", "Basic " + authorization);
135 httpEntity = new HttpEntity(headers);
137 ResponseEntity responseEntity;
140 restTemplate.exchange(baseUrl + "/aai/schema-service/v1/nodes?version=blah",
141 HttpMethod.GET, httpEntity, String.class);
142 System.out.println(" " + responseEntity.getBody());
143 assertThat(responseEntity.getStatusCodeValue(), is(400));
145 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
146 headers.setContentType(MediaType.APPLICATION_JSON);
147 httpEntity = new HttpEntity(headers);
150 restTemplate.exchange(baseUrl + "/aai/schema-service/v1/edgerules?version=blah",
151 HttpMethod.GET, httpEntity, String.class);
153 assertThat(responseEntity.getStatusCodeValue(), is(400));
157 public void testVersions() {
159 ResponseEntity responseEntity;
161 responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/versions",
162 HttpMethod.GET, httpEntity, String.class);
163 assertThat(responseEntity.getStatusCodeValue(), is(200));
168 public void testGetStoredQueriesSuccess() {
170 ResponseEntity responseEntity;
172 responseEntity = restTemplate.exchange(baseUrl + "/aai/schema-service/v1/stored-queries",
173 HttpMethod.GET, httpEntity, String.class);
174 assertThat(responseEntity.getStatusCodeValue(), is(200));