Merge "[AAI] Improve test coverage for A&AI component aai-schema-service"
[aai/schema-service.git] / aai-queries / src / test / java / org / onap / aai / queries / AAISetup.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.queries;
22
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.nio.charset.Charset;
28 import java.util.Map;
29
30 import org.apache.commons.io.IOUtils;
31 import org.junit.jupiter.api.BeforeAll;
32 import org.onap.aai.config.IntrospectionConfig;
33 import org.onap.aai.config.RestBeanConfig;
34 import org.onap.aai.config.SpringContextAware;
35 import org.onap.aai.edges.EdgeIngestor;
36 import org.onap.aai.introspection.LoaderFactory;
37 import org.onap.aai.introspection.MoxyLoader;
38 import org.onap.aai.nodes.NodeIngestor;
39 import org.onap.aai.rest.db.HttpEntry;
40 import org.onap.aai.serialization.db.EdgeSerializer;
41 import org.onap.aai.setup.AAIConfigTranslator;
42 import org.onap.aai.setup.SchemaLocationsBean;
43 import org.onap.aai.setup.SchemaVersion;
44 import org.onap.aai.setup.SchemaVersions;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.beans.factory.annotation.Value;
47 import org.springframework.test.context.TestPropertySource;
48 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
49
50 @SpringJUnitConfig(
51     classes = {SchemaLocationsBean.class, SchemaVersions.class, AAIConfigTranslator.class,
52         EdgeIngestor.class, EdgeSerializer.class, NodeIngestor.class, SpringContextAware.class,
53         IntrospectionConfig.class, RestBeanConfig.class, GremlinServerSingleton.class})
54 @TestPropertySource(
55     properties = {"schema.uri.base.path = /aai",
56         "schema.ingest.file = src/test/resources/application-test.properties"})
57 public abstract class AAISetup {
58     @Autowired
59     protected NodeIngestor nodeIngestor;
60
61     @Autowired
62     protected LoaderFactory loaderFactory;
63
64     @Autowired
65     protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance;
66
67     @Autowired
68     protected HttpEntry traversalHttpEntry;
69
70     @Autowired
71     protected HttpEntry traversalUriHttpEntry;
72
73     @Autowired
74     protected EdgeSerializer edgeSer;
75
76     @Autowired
77     protected EdgeIngestor edgeIngestor;
78
79     @Autowired
80     protected SchemaVersions schemaVersions;
81
82     @Autowired
83     protected GremlinServerSingleton gremlinServerSingleton;
84
85     @Value("${schema.uri.base.path}")
86     protected String basePath;
87
88     @BeforeAll
89     public static void setupBundleconfig() throws Exception {
90         System.setProperty("AJSC_HOME", "./");
91         System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/");
92
93     }
94
95     public String getPayload(String filename) throws IOException {
96
97         InputStream inputStream = getClass().getClassLoader().getResourceAsStream(filename);
98
99         String message = String.format("Unable to find the %s in src/test/resources", filename);
100         assertNotNull(inputStream, message);
101
102         String resource = IOUtils.toString(inputStream, Charset.defaultCharset());
103         return resource;
104     }
105 }