1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 package org.oran.otf.api.tests.config;
\r
19 import com.mongodb.MongoClient;
\r
20 import com.mongodb.MongoClientOptions;
\r
21 import com.mongodb.MongoCredential;
\r
22 import com.mongodb.ServerAddress;
\r
23 import de.flapdoodle.embed.mongo.Command;
\r
24 import de.flapdoodle.embed.mongo.MongodExecutable;
\r
25 import de.flapdoodle.embed.mongo.MongodStarter;
\r
26 import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder;
\r
27 import de.flapdoodle.embed.mongo.config.ExtractedArtifactStoreBuilder;
\r
28 import de.flapdoodle.embed.mongo.config.IMongodConfig;
\r
29 import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
\r
30 import de.flapdoodle.embed.mongo.config.Net;
\r
31 import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
\r
32 import de.flapdoodle.embed.mongo.distribution.Version;
\r
33 import de.flapdoodle.embed.process.config.IRuntimeConfig;
\r
34 import de.flapdoodle.embed.process.config.store.HttpProxyFactory;
\r
35 import de.flapdoodle.embed.process.runtime.Network;
\r
36 import org.springframework.beans.factory.annotation.Value;
\r
37 import org.springframework.boot.autoconfigure.AutoConfigureBefore;
\r
38 import org.springframework.context.annotation.Bean;
\r
39 import org.springframework.context.annotation.Configuration;
\r
40 import org.springframework.context.annotation.Profile;
\r
41 import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
\r
42 import org.springframework.data.mongodb.core.MongoTemplate;
\r
43 import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
\r
47 @EnableMongoRepositories(basePackages = "org.oran.otf.common.repository")
\r
49 public class DataConfig2 extends AbstractMongoConfiguration {
\r
51 @Value("${otf.embedded.host}")
\r
52 private String host;
\r
54 @Value("${otf.embedded.port}")
\r
58 @Value("${otf.embedded.database}")
\r
59 private String database;
\r
61 public DataConfig2(){
\r
65 protected String getDatabaseName() {
\r
71 public MongoClient mongoClient() {
\r
72 MongoCredential credential = MongoCredential.createScramSha1Credential(username, database, password.toCharArray());
\r
74 MongoClientOptions options = MongoClientOptions
\r
77 .requiredReplicaSetName(replicaSet)
\r
80 String[] hostArray = hosts.split(",");
\r
81 ArrayList<ServerAddress> hosts = new ArrayList<>();
\r
83 for (String host : hostArray) {
\r
84 String[] hostSplit = host.split(":");
\r
85 hosts.add(new ServerAddress(hostSplit[0], Integer.parseInt(hostSplit[1])));
\r
88 return new MongoClient(hosts, credential, options);
\r
93 MongoTemplate mongoTemplate() {
\r
94 return new MongoTemplate(mongoClient(), database);
\r
99 public MongoClient mongoClient(){
\r
100 return new MongoClient();
\r
104 public @Bean MongoTemplate mongoTemplate(){
\r
105 return new MongoTemplate(new MongoClient(host, port), "test");
\r