aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/aai/cacher/Application.java7
-rw-r--r--src/main/java/org/onap/aai/cacher/common/MongoConfig.java27
-rw-r--r--src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java67
-rw-r--r--src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java29
-rw-r--r--src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java88
-rw-r--r--src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java66
-rw-r--r--src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java25
-rw-r--r--src/main/java/org/onap/aai/cacher/util/RestClient.java2
-rw-r--r--src/main/java/org/onap/aai/cacher/web/JerseyConfiguration.java4
-rw-r--r--src/main/java/org/onap/aai/cacher/web/LocalHostAccessLog.java10
-rw-r--r--src/main/resources/application.properties10
-rw-r--r--src/test/java/org/onap/aai/cacher/common/LimitTest.java14
-rw-r--r--src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonNoFakeTest.java9
-rw-r--r--src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonTest.java20
-rw-r--r--src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIDmaapEventProcessorScenariosTest.java14
-rw-r--r--src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIEventConsumerTest.java16
-rw-r--r--src/test/java/org/onap/aai/cacher/injestion/parser/AAIResourcesUriTemplatesTest.java14
-rw-r--r--src/test/java/org/onap/aai/cacher/injestion/parser/PayloadParserServiceTest.java25
-rw-r--r--src/test/java/org/onap/aai/cacher/service/helper/CacheHelperServiceScenariosTest.java16
-rw-r--r--src/test/java/org/onap/aai/cacher/service/helper/CrudOperationsTest.java14
20 files changed, 274 insertions, 203 deletions
diff --git a/src/main/java/org/onap/aai/cacher/Application.java b/src/main/java/org/onap/aai/cacher/Application.java
index 6d40b68..e2dbca9 100644
--- a/src/main/java/org/onap/aai/cacher/Application.java
+++ b/src/main/java/org/onap/aai/cacher/Application.java
@@ -28,9 +28,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -39,7 +40,7 @@ import java.util.UUID;
@SpringBootApplication
@EnableScheduling
-@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
+@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class})
@ComponentScan(basePackages = { "org.onap.aai.cacher", "com" })
public class Application extends SpringBootServletInitializer {
@@ -65,7 +66,7 @@ public class Application extends SpringBootServletInitializer {
LoggingContext.statusCode(StatusCode.COMPLETE);
SpringApplication app = new SpringApplication(Application.class);
- app.setLogStartupInfo(false);
+ app.setLogStartupInfo(true);
app.setRegisterShutdownHook(true);
app.addInitializers(new PropertyPasswordConfiguration());
app.run(args);
diff --git a/src/main/java/org/onap/aai/cacher/common/MongoConfig.java b/src/main/java/org/onap/aai/cacher/common/MongoConfig.java
index 5c1a541..854437d 100644
--- a/src/main/java/org/onap/aai/cacher/common/MongoConfig.java
+++ b/src/main/java/org/onap/aai/cacher/common/MongoConfig.java
@@ -28,7 +28,10 @@ import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.*;
+import de.flapdoodle.embed.mongo.config.Defaults;
+import de.flapdoodle.embed.mongo.config.MongoCmdOptions;
+import de.flapdoodle.embed.mongo.config.MongodConfig;
+import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.config.io.ProcessOutput;
import de.flapdoodle.embed.process.io.Processors;
@@ -48,22 +51,21 @@ import java.io.IOException;
@Configuration
public class MongoConfig {
- private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoConfig.class);
+ private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoConfig.class);
- @Value("${mongodb.host}")
+ @Value("${spring.data.mongodb.host}")
private String MONGO_DB_HOST;
- @Value("${mongodb.dbName}")
+ @Value("${spring.data.mongodb.database}")
private String MONGO_DB_NAME;
- @Value("${mongodb.port}")
+ @Value("${spring.data.mongodb.port}")
private int MONGO_DB_PORT;
private MongodProcess mongod;
@Bean
public MongoClient mongoClient(MongodProcess mongodProcess) {
- try {
- // To connect to mongodb server
- MongoClient mongoC = new MongoClient(MONGO_DB_HOST, MONGO_DB_PORT);
+ // To connect to mongodb server
+ try (MongoClient mongoC = new MongoClient(MONGO_DB_HOST, MONGO_DB_PORT)) {
// Now connect to your databases
EELF_LOGGER.info("Connect to database successfully");
@@ -94,19 +96,18 @@ public class MongoConfig {
Logger logger = LoggerFactory.getLogger("mongo");
int port = MONGO_DB_PORT;
- IMongodConfig mongoConfigConfig = new MongodConfigBuilder()
+ MongodConfig mongoConfigConfig = MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(new Net(port, Network.localhostIsIPv6()))
- .cmdOptions(new MongoCmdOptionsBuilder().enableTextSearch(true).useNoPrealloc(false).build())
- .configServer(false)
+ .cmdOptions(MongoCmdOptions.builder().enableTextSearch(true).useNoPrealloc(false).build())
+ .isConfigServer(false)
.build();
ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.WARN), Processors.logTo(logger,
Slf4jLevel.WARN), Processors.logTo(logger, Slf4jLevel.WARN));
MongodExecutable mongodExecutable = MongodStarter
- .getInstance((new RuntimeConfigBuilder())
- .defaults(Command.MongoD)
+ .getInstance(Defaults.runtimeConfigFor(Command.MongoD)
.processOutput(processOutput)
.build())
.prepare(mongoConfigConfig);
diff --git a/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java b/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java
index a94f36a..3b52a00 100644
--- a/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java
+++ b/src/main/java/org/onap/aai/cacher/common/MongoHelperSingleton.java
@@ -57,7 +57,11 @@ import java.util.stream.Collectors;
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class MongoHelperSingleton {
- private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoHelperSingleton.class);
+ public static final String AAI_4000_LBL = "AAI_4000";
+
+ public static final String AAI_5105_LBL = "AAI_5105";
+
+ private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(MongoHelperSingleton.class);
private DB db;
@@ -80,7 +84,7 @@ public class MongoHelperSingleton {
db.getCollection(name);
EELF_LOGGER.info("Collection " + name + " created successfully");
} catch (Exception e) {
- AAIException aaiException = new AAIException("AAI_4000");
+ AAIException aaiException = new AAIException(AAI_4000_LBL);
ErrorLogHelper.logException(aaiException);
}
}
@@ -100,11 +104,11 @@ public class MongoHelperSingleton {
return false;
}
} catch (MongoException ex) {
- AAIException aaiException = new AAIException("AAI_5105");
+ AAIException aaiException = new AAIException(AAI_5105_LBL);
ErrorLogHelper.logException(aaiException);
return false;
} catch (Exception e) {
- AAIException aaiException = new AAIException("AAI_4000");
+ AAIException aaiException = new AAIException(AAI_4000_LBL);
ErrorLogHelper.logException(aaiException);
return false;
}
@@ -118,11 +122,11 @@ public class MongoHelperSingleton {
result = collection.update(searchQuery, (BasicDBObject) document, updateOptions);
return result.wasAcknowledged();
} catch (MongoException ex) {
- AAIException aaiException = new AAIException("AAI_5105");
+ AAIException aaiException = new AAIException(AAI_5105_LBL);
ErrorLogHelper.logException(aaiException);
return false;
} catch (Exception e) {
- AAIException aaiException = new AAIException("AAI_4000");
+ AAIException aaiException = new AAIException(AAI_4000_LBL);
ErrorLogHelper.logException(aaiException);
return false;
}
@@ -144,7 +148,7 @@ public class MongoHelperSingleton {
return "NOT_FOUND";
}
} catch (MongoException ex) {
- AAIException aaiException = new AAIException("AAI_5105");
+ AAIException aaiException = new AAIException(AAI_5105_LBL);
ErrorLogHelper.logException(aaiException);
return "EXCEPTION_THROWN";
}
@@ -266,7 +270,6 @@ public class MongoHelperSingleton {
protected void mongoPull(CacheEntry cacheEntry, MongoCollection<Document> collection, Document nestedFind) {
CacheEntry localCacheEntry = CacheEntry.CacheEntryBuilder.createCacheEntry().deepCopy(cacheEntry).build();
- ArrayList<Document> filters = this.getFiltersAndUpdateNestedField(localCacheEntry);
Document pullObj = new Document();
pullObj.put(localCacheEntry.getNestedField(),
@@ -275,42 +278,46 @@ public class MongoHelperSingleton {
pull.put("$pull", pullObj);
collection.findOneAndUpdate(nestedFind, pull, new FindOneAndUpdateOptions().upsert(true));
// TODO remove wrapping if there are no entries in array.
-
}
private ArrayList<Document> getFiltersAndUpdateNestedField(CacheEntry cacheEntry) {
-
- if (StringUtils.countMatches(cacheEntry.getNestedField(), ".$.") < 2) {
- return new ArrayList<>();
- }
-
ArrayList<Document> filters = new ArrayList<>();
- List<String> keys = cacheEntry.getNestedFind().entrySet().stream().map(Map.Entry::getKey)
- .filter(s -> !s.equals("_id")).sorted((s, t1) -> {
- if (StringUtils.countMatches(s, ".") > StringUtils.countMatches(t1, ".")) {
- return 1;
- }
- return s.compareTo(t1);
- }).collect(Collectors.toList());
String filterKey;
String filterValue;
String key;
char filterIndex = 'a';
StringBuilder newNestedField = new StringBuilder();
+
+ if (StringUtils.countMatches(cacheEntry.getNestedField(), ".$.") < 2) {
+ return new ArrayList<>();
+ }
+
+ List<String> keys = cacheEntry.getNestedFind().entrySet().stream()
+ .map(Map.Entry::getKey)
+ .filter(s -> !s.equals("_id")).sorted((s, t1) -> {
+ if (StringUtils.countMatches(s, ".") > StringUtils.countMatches(t1, ".")) {
+ return 1;
+ }
+ return s.compareTo(t1);
+ }).collect(Collectors.toList());
List<String> fieldSplit = Arrays.asList(cacheEntry.getNestedField().split("\\.\\$"));
+
for (int i = 0; i < fieldSplit.size(); i++) {
final String subSplit = StringUtils.join(fieldSplit.subList(0, i + 1), "");
- key = keys.stream().filter(s -> s.startsWith(subSplit)).findFirst().get();
- filterIndex += i;
- filterKey = filterIndex + "." + key.substring(key.lastIndexOf(".") + 1);
- filterValue = cacheEntry.getNestedFind().get(key).getAsString();
- newNestedField.append(fieldSplit.get(i));
- if (i + 1 != fieldSplit.size()) {
- newNestedField.append(".$[").append(filterIndex).append("]");
- filters.add(new Document().append(filterKey, filterValue));
+ Optional<String> keyOpt = keys.stream().filter(s -> s.startsWith(subSplit)).findFirst();
+ if (keyOpt.isPresent()) {
+ key = keyOpt.get();
+ filterIndex += i;
+ filterKey = filterIndex + "." + key.substring(key.lastIndexOf(".") + 1);
+ filterValue = cacheEntry.getNestedFind().get(key).getAsString();
+ newNestedField.append(fieldSplit.get(i));
+ if (i + 1 != fieldSplit.size()) {
+ newNestedField.append(".$[").append(filterIndex).append("]");
+ filters.add(new Document().append(filterKey, filterValue));
+ }
}
-
}
+
cacheEntry.setNestedField(newNestedField.toString());
return filters;
diff --git a/src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java b/src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java
new file mode 100644
index 0000000..d47541b
--- /dev/null
+++ b/src/main/java/org/onap/aai/cacher/exceptions/MissingTemplateException.java
@@ -0,0 +1,29 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2020 Bell Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.cacher.exceptions;
+
+public class MissingTemplateException extends RuntimeException {
+
+ public static final String DEFAULT_EXCEPTION_MESSAGE = "Failed in uriToTemplates for truncatedUri '%s'";
+
+ public MissingTemplateException(String uri) {
+ super(String.format(DEFAULT_EXCEPTION_MESSAGE, uri));
+ }
+}
diff --git a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java
index 887e4d3..0a4c931 100644
--- a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java
+++ b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/AAIResourcesUriTemplates.java
@@ -24,6 +24,7 @@ import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonObject;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.annotations.Metadata;
+import org.onap.aai.cacher.exceptions.MissingTemplateException;
import org.onap.aai.cacher.util.AAIConstants;
import org.reflections.Reflections;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -44,7 +45,7 @@ import java.util.*;
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class AAIResourcesUriTemplates {
- private final static EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourcesUriTemplates.class);
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourcesUriTemplates.class);
private final Map<String, String> typeToUriTemplate;
@@ -63,13 +64,13 @@ public class AAIResourcesUriTemplates {
Reflections reflections = new Reflections("org.onap.aai.domain.yang");
reflections.getTypesAnnotatedWith(Metadata.class)
- .stream()
- .filter(aClass -> "org.onap.aai.domain.yang".equals(aClass.getPackage().getName()))
- .filter(aClass -> !aClass.getAnnotation(Metadata.class).uriTemplate().isEmpty())
- .forEach(aClass -> typeToUriTemplate.put(
- aClass.getAnnotation(XmlRootElement.class).name(),
- aClass.getAnnotation(Metadata.class).uriTemplate())
- );
+ .stream()
+ .filter(aClass -> "org.onap.aai.domain.yang".equals(aClass.getPackage().getName()))
+ .filter(aClass -> !aClass.getAnnotation(Metadata.class).uriTemplate().isEmpty())
+ .forEach(aClass -> typeToUriTemplate.put(
+ aClass.getAnnotation(XmlRootElement.class).name(),
+ aClass.getAnnotation(Metadata.class).uriTemplate())
+ );
LOGGER.info("AAI uri templates: " + typeToUriTemplate);
}
@@ -80,7 +81,7 @@ public class AAIResourcesUriTemplates {
/**
* Get templated aai uri segment by type.
- *
+ *
* @param type
* @return
*/
@@ -90,6 +91,7 @@ public class AAIResourcesUriTemplates {
/**
* For the given template and uri get the variable key value pairs
+ *
* @param uri
* @param template
* @return
@@ -106,7 +108,7 @@ public class AAIResourcesUriTemplates {
/**
* For a given uri get an ordered list of templates.
- *
+ *
* @param uri
* @return
*/
@@ -118,19 +120,20 @@ public class AAIResourcesUriTemplates {
while (truncatedUri.contains("/")) {
matchingStartingTemplate = this.getMatchingStartingTemplate(truncatedUri);
- if ( !matchingStartingTemplate.isPresent()) {
+ if (!matchingStartingTemplate.isPresent()) {
LOGGER.error("failed in uriToTemplates for truncatedUri " + truncatedUri);
- // exception expected for missing template
- }
- template = matchingStartingTemplate.get();
- uriTemplateList.add(template);
- int count = StringUtils.countMatches(template, "/");
- if (count < StringUtils.countMatches(truncatedUri, "/")) {
- truncatedUri = StringUtils.substring(
+ throw new MissingTemplateException(truncatedUri);
+ } else {
+ template = matchingStartingTemplate.get();
+ uriTemplateList.add(template);
+ int count = StringUtils.countMatches(template, "/");
+ if (count < StringUtils.countMatches(truncatedUri, "/")) {
+ truncatedUri = StringUtils.substring(
truncatedUri,
StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1));
- } else {
- truncatedUri = "";
+ } else {
+ truncatedUri = "";
+ }
}
}
@@ -139,7 +142,7 @@ public class AAIResourcesUriTemplates {
/**
* For a given uri get an ordered list of templates.
- *
+ *
* @param uri
* @return
*/
@@ -149,14 +152,17 @@ public class AAIResourcesUriTemplates {
String truncatedUri = uri;
while (truncatedUri.contains("/")) {
- template = this.getMatchingStartingTemplate(truncatedUri).get();
- int count = StringUtils.countMatches(template, "/");
- int cutIndex = truncatedUri.length();
- if (count != StringUtils.countMatches(truncatedUri, "/")) {
- cutIndex = StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1);
+ Optional<String> templateOpt = this.getMatchingStartingTemplate(truncatedUri);
+ if (templateOpt.isPresent()) {
+ template = templateOpt.get();
+ int count = StringUtils.countMatches(template, "/");
+ int cutIndex = truncatedUri.length();
+ if (count != StringUtils.countMatches(truncatedUri, "/")) {
+ cutIndex = StringUtils.ordinalIndexOf(truncatedUri, "/", count + 1);
+ }
+ uriList.add(StringUtils.substring(truncatedUri, 0, cutIndex));
+ truncatedUri = StringUtils.substring(truncatedUri, cutIndex);
}
- uriList.add(StringUtils.substring(truncatedUri, 0, cutIndex));
- truncatedUri = StringUtils.substring(truncatedUri, cutIndex);
}
return uriList;
@@ -164,7 +170,7 @@ public class AAIResourcesUriTemplates {
/**
* returns the template matching the start of the uri.
- *
+ *
* @param uri
* @return @see java.util.Optional
*/
@@ -174,7 +180,7 @@ public class AAIResourcesUriTemplates {
/**
* Given aai type and json object generate the uri for it.
- *
+ *
* @param type
* @param jo
* @return
@@ -190,7 +196,7 @@ public class AAIResourcesUriTemplates {
/**
* Get encoded values from json object for each key in keys
- *
+ *
* @param keys
* @param jo
* @return
@@ -204,7 +210,7 @@ public class AAIResourcesUriTemplates {
/**
* extract uri keys from the templated uri
- *
+ *
* @param template
* @return
*/
@@ -216,30 +222,22 @@ public class AAIResourcesUriTemplates {
/**
* UTF-8 encoding of @param string
- *
+ *
* @param string string to be encoded
* @return
*/
public String encodeProp(String string) {
- try {
- return UriUtils.encode(string, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- return "";
- }
+ return UriUtils.encode(string, "UTF-8");
}
/**
* UTF-8 decoding of @param string
- *
+ *
* @param string string to be encoded
* @return
*/
public String decodeProp(String string) {
- try {
- return UriUtils.decode(string, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- return "";
- }
+ return UriUtils.decode(string, "UTF-8");
}
public String getAAIUriFromEntityUri(String fullUri) {
@@ -260,7 +258,7 @@ public class AAIResourcesUriTemplates {
for (int i = 0; i < uriSegments.size(); i++) {
aus = new AAIUriSegment(uriSegments.get(i), uriSegmentTemplates.get(i));
aus.setSegmentKeyValues(
- getUriTemplateMappings(aus.getSegment(), aus.getSegmentTemplate()));
+ getUriTemplateMappings(aus.getSegment(), aus.getSegmentTemplate()));
uriSegmentList.add(aus);
}
return uriSegmentList;
diff --git a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java
index 8d88a4a..d879314 100644
--- a/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java
+++ b/src/main/java/org/onap/aai/cacher/injestion/parser/strategy/aai/dmaap/AAIResourceDmaapParserStrategy.java
@@ -48,7 +48,9 @@ import java.util.stream.Collectors;
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadParserStrategy {
- private final static EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourceDmaapParserStrategy.class);
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIResourceDmaapParserStrategy.class);
+
+ public static final String RELATED_LINK_PROPERTY_KEY = "related-link";
@Autowired
public AAIResourceDmaapParserStrategy(AAIResourcesUriTemplates aaiResourcesUriTemplates) {
@@ -133,7 +135,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
private CacheEntry getParentUpdateCacheEntry(String topEntityType, String entityUri, DmaapAction actionType, List<AAIUriSegment> uriSegments) {
String parentUri = String.join(
"",
- uriSegments.stream().limit(uriSegments.size()-1).map(AAIUriSegment::getSegment).collect(Collectors.toList()));
+ uriSegments.stream().limit(uriSegments.size()-1L).map(AAIUriSegment::getSegment).collect(Collectors.toList()));
JsonObject findQuery = new JsonObject();
findQuery.addProperty("_id", parentUri);
JsonObject nestedFindQuery = new JsonObject();
@@ -181,10 +183,10 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
findQuery.addProperty("_id", uri);
JsonObject nestedFindQuery = new JsonObject();
nestedFindQuery.addProperty("_id", uri);
- nestedFindQuery.addProperty("relationship-list.relationship.related-link", entity.get("related-link").getAsString());
+ nestedFindQuery.addProperty("relationship-list.relationship.related-link", entity.get(RELATED_LINK_PROPERTY_KEY).getAsString());
String nestedField = "relationship-list.relationship";
JsonObject nestedIdentifier = new JsonObject();
- nestedIdentifier.addProperty("related-link", entity.get("related-link").getAsString());
+ nestedIdentifier.addProperty(RELATED_LINK_PROPERTY_KEY, entity.get(RELATED_LINK_PROPERTY_KEY).getAsString());
return CacheEntry.CacheEntryBuilder.createCacheEntry().inCollection(collection).withDbAction(actionType.getDbAction())
.withId(uri).isNested(true).withPayload(entity).withFindQuery(findQuery)
@@ -197,18 +199,17 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
existingCacheEntriesRelationships.forEach((k, v) -> {
if (cacheEntriesRelationships.containsKey(k)) {
v.forEach(oldA -> {
- int found = -1;
- for (int i = 0; i < cacheEntriesRelationships.get(k).size(); i++) {
- if (cacheEntriesRelationships.get(k).get(i).getFullUri().equals(oldA.getFullUri())) {
- found = i;
- break;
- }
- }
- if (found != -1) {
- cacheEntriesRelationships.get(k).remove(cacheEntriesRelationships.get(k).get(found));
+ List<AAIRelatedToDetails> cacheEntriesRelationshipsForK = cacheEntriesRelationships.get(k);
+
+ Optional<AAIRelatedToDetails> foundEntryOpt = cacheEntriesRelationshipsForK.stream()
+ .filter(entry -> entry.getFullUri().equals(oldA.getFullUri()))
+ .findFirst();
+
+ if (foundEntryOpt.isPresent()) {
+ cacheEntriesRelationshipsForK.remove(foundEntryOpt.get());
} else {
oldA.setActionType(DmaapAction.DELETE);
- cacheEntriesRelationships.get(k).add(oldA);
+ cacheEntriesRelationshipsForK.add(oldA);
}
});
} else {
@@ -231,7 +232,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
JsonArray relationships = e.getValue().getAsJsonObject().getAsJsonArray("relationship");
for (JsonElement relationship : relationships) {
relationshipMapping.add(fullUriPrefix + cacheEntry.getId(), new AAIRelatedToDetails(
- relationship.getAsJsonObject().get("related-link").getAsString(),
+ relationship.getAsJsonObject().get(RELATED_LINK_PROPERTY_KEY).getAsString(),
relationship.getAsJsonObject().get("relationship-label").getAsString(), actionType));
}
}
@@ -256,7 +257,7 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
if (label != null) {
relObj.addProperty("relationship-label", label);
}
- relObj.addProperty("related-link", fullUri);
+ relObj.addProperty(RELATED_LINK_PROPERTY_KEY, fullUri);
for (AAIUriSegment aaiUriSegment : uriSegmentList) {
aaiUriSegment.getSegmentKeyValues().forEach((k, v) -> {
@@ -281,35 +282,35 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
if (uriSegments.size() > 1) {
Optional<String> segmentPlural;
String segmentSingular;
- String jsonStr;
JsonObject jsonObj;
JsonArray jsonArray;
- JsonElement jsonElement;
for (int i = 1; i < uriSegments.size(); i++) {
+ segmentPlural = uriSegments.get(i).getSegmentPlural();
+ segmentSingular = uriSegments.get(i).getSegmentSingular();
- if (uriSegments.get(i).getSegmentPlural().isPresent()) {
- segmentPlural = uriSegments.get(i).getSegmentPlural();
- segmentSingular = uriSegments.get(i).getSegmentSingular();
- if ( segmentSingular.equals("cvlan-tag")) {
- // map to what is in the entity
+ if (segmentPlural.isPresent()) {
+ if (segmentSingular.equals("cvlan-tag")) {
+ // map to what is in the entity
segmentSingular = "cvlan-tag-entry";
}
- jsonObj = entityBody.getAsJsonObject(uriSegments.get(i).getSegmentPlural().get());
+ jsonObj = entityBody.getAsJsonObject(segmentPlural.get());
jsonArray = jsonObj.getAsJsonArray(segmentSingular);
- if ( jsonArray == null ) {
- LOGGER.error("failed in getWrappedEntityObject " + segmentSingular + " not found in " + jsonObj );
+ if (jsonArray == null) {
+ LOGGER
+ .error("failed in getWrappedEntityObject " + segmentSingular + " not found in " + jsonObj);
// exception expected for missing template
+ } else {
+ entityBody = jsonArray.get(0).getAsJsonObject();
+ arrayKey = segmentSingular;
}
- entityBody = jsonArray.get(0).getAsJsonObject();
- arrayKey = uriSegments.get(i).getSegmentSingular();
} else {
- entityBody = entityBody.getAsJsonArray(uriSegments.get(i).getSegmentSingular()).get(0).getAsJsonObject();
- arrayKey = uriSegments.get(i).getSegmentSingular();
+ entityBody = entityBody.getAsJsonArray(segmentSingular).get(0).getAsJsonObject();
+ arrayKey = segmentSingular;
}
-
}
}
+
arrayWrapper.add(entityBody);
objectWrapper.add(arrayKey, arrayWrapper);
return objectWrapper;
@@ -321,7 +322,4 @@ public class AAIResourceDmaapParserStrategy extends AAIResourceGetAllPayloadPars
}
return String.join("", uriSegments.subList(0, uriSegments.size()-1).stream().map(AAIUriSegment::getSegment).collect(Collectors.toList()));
}
-
-
-
} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java b/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java
index 2a9a403..3f09124 100644
--- a/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java
+++ b/src/main/java/org/onap/aai/cacher/service/tasks/ScheduledTaskConfig.java
@@ -31,18 +31,18 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.IntervalTask;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
-import java.text.SimpleDateFormat;
import java.util.Date;
@Configuration
public class ScheduledTaskConfig {
- private final static EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(ScheduledTaskConfig.class);
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
- private final static int THREAD_POOL_SIZE = 10;
- private final static String THREAD_POOL_PREFIX = "poolScheduler";
- private final static int TASK_INTERVAL_TIME = 30000;
- private final static int TASK_DELAY_TIME = 0;
+ private static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(ScheduledTaskConfig.class);
+ private static final int THREAD_POOL_SIZE = 10;
+ private static final String THREAD_POOL_PREFIX = "poolScheduler";
+ private static final int TASK_INTERVAL_TIME = 30000;
+ private static final int TASK_DELAY_TIME = 0;
+
+ //private ScheduledTaskConfig(){}
@Configuration
static class RegisterTaskSchedulerViaSchedulingConfigurer implements SchedulingConfigurer {
@@ -53,13 +53,10 @@ public class ScheduledTaskConfig {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setTaskScheduler(poolScheduler());
- taskRegistrar.addFixedRateTask(new IntervalTask(new Runnable() {
- @Override
- public void run() {
- EELF_LOGGER.info(
- "Job @ fixed rate " + new Date() + ", Thread name is " + Thread.currentThread().getName());
- chs.checkAndInitTasks();
- }
+ taskRegistrar.addFixedRateTask(new IntervalTask(() -> {
+ EELF_LOGGER.info(
+ "Job @ fixed rate " + new Date() + ", Thread name is " + Thread.currentThread().getName());
+ chs.checkAndInitTasks();
}, TASK_INTERVAL_TIME, TASK_DELAY_TIME));
}
diff --git a/src/main/java/org/onap/aai/cacher/util/RestClient.java b/src/main/java/org/onap/aai/cacher/util/RestClient.java
index 9613d81..f836287 100644
--- a/src/main/java/org/onap/aai/cacher/util/RestClient.java
+++ b/src/main/java/org/onap/aai/cacher/util/RestClient.java
@@ -125,7 +125,7 @@ public class RestClient {
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {
- RestTemplate restTemplate = builder.requestFactory(new HttpComponentsClientHttpRequestFactory(restClient))
+ RestTemplate restTemplate = builder.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(restClient))
.build();
restTemplate.setErrorHandler(new ResponseErrorHandler() {
diff --git a/src/main/java/org/onap/aai/cacher/web/JerseyConfiguration.java b/src/main/java/org/onap/aai/cacher/web/JerseyConfiguration.java
index b18e840..d0a15cd 100644
--- a/src/main/java/org/onap/aai/cacher/web/JerseyConfiguration.java
+++ b/src/main/java/org/onap/aai/cacher/web/JerseyConfiguration.java
@@ -19,7 +19,7 @@
*/
package org.onap.aai.cacher.web;
-import org.glassfish.jersey.filter.LoggingFilter;
+import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.onap.aai.cacher.service.rest.CacheInteractionService;
import org.onap.aai.cacher.service.rest.CacheKeyService;
@@ -60,7 +60,7 @@ public class JerseyConfiguration extends ResourceConfig {
// If the LoggingFilter second argument is set to true, it will print response
// value as well
if ("true".equalsIgnoreCase(env.getProperty("aai.request.logging.enabled"))) {
- register(new LoggingFilter(log, false));
+ register(new LoggingFeature(log, 0));
}
}
diff --git a/src/main/java/org/onap/aai/cacher/web/LocalHostAccessLog.java b/src/main/java/org/onap/aai/cacher/web/LocalHostAccessLog.java
index 81addb5..ff7d79f 100644
--- a/src/main/java/org/onap/aai/cacher/web/LocalHostAccessLog.java
+++ b/src/main/java/org/onap/aai/cacher/web/LocalHostAccessLog.java
@@ -22,9 +22,9 @@ package org.onap.aai.cacher.web;
import ch.qos.logback.access.jetty.RequestLogImpl;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
-import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer;
+import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
+import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,8 +34,8 @@ import java.util.Arrays;
public class LocalHostAccessLog {
@Bean
- public EmbeddedServletContainerFactory jettyConfigBean() {
- JettyEmbeddedServletContainerFactory jef = new JettyEmbeddedServletContainerFactory();
+ public AbstractServletWebServerFactory jettyConfigBean() {
+ JettyServletWebServerFactory jef = new JettyServletWebServerFactory();
jef.addServerCustomizers((JettyServerCustomizer) server -> {
HandlerCollection handlers = new HandlerCollection();
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index cd51b92..1937032 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -8,7 +8,7 @@ spring.jersey.type=filter
spring.mvc.urls=swagger,docs,prometheus
-server.contextPath=/
+server.servlet.context-path=/
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
spring.profiles.active=production,one-way-ssl
@@ -36,7 +36,7 @@ archetype.name=sdk-java-jersey-archetype
server.local.startpath=src/main/resources/
server.basic.auth.location=${server.local.startpath}etc/auth/realm.properties
-server.port = 8444
+server.port=8444
server.ssl.enabled-protocols=TLSv1.1,TLSv1.2
server.ssl.key-store=${server.local.startpath}etc/auth/aai_keystore
server.ssl.key-store-password=password(OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0)
@@ -46,9 +46,9 @@ server.ssl.client-auth=want
server.ssl.key-store-type=JKS
#mongodb configuration values
-mongodb.host=localhost
-mongodb.dbName=aai
-mongodb.port=27017
+spring.data.mongodb.host=localhost
+spring.data.mongodb.database=aai
+spring.data.mongodb.port=27017
#logging configurations
aai.transaction.logging=true
diff --git a/src/test/java/org/onap/aai/cacher/common/LimitTest.java b/src/test/java/org/onap/aai/cacher/common/LimitTest.java
index 366181d..2753ca2 100644
--- a/src/test/java/org/onap/aai/cacher/common/LimitTest.java
+++ b/src/test/java/org/onap/aai/cacher/common/LimitTest.java
@@ -30,7 +30,10 @@ import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.*;
+import de.flapdoodle.embed.mongo.config.Defaults;
+import de.flapdoodle.embed.mongo.config.MongoCmdOptions;
+import de.flapdoodle.embed.mongo.config.MongodConfig;
+import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.config.io.ProcessOutput;
import de.flapdoodle.embed.process.io.Processors;
@@ -111,19 +114,18 @@ public class LimitTest {
protected static void startEmbedded(int port) throws IOException {
Logger logger = LoggerFactory.getLogger("mongo");
- IMongodConfig mongoConfigConfig = new MongodConfigBuilder()
+ MongodConfig mongoConfigConfig = MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(new Net(port, Network.localhostIsIPv6()))
- .cmdOptions(new MongoCmdOptionsBuilder().enableTextSearch(true).useNoPrealloc(false).build())
- .configServer(false)
+ .cmdOptions(MongoCmdOptions.builder().enableTextSearch(true).useNoPrealloc(false).build())
+ .isConfigServer(false)
.build();
ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.WARN), Processors.logTo(logger,
Slf4jLevel.WARN), Processors.logTo(logger, Slf4jLevel.WARN));
MongodExecutable mongodExecutable = MongodStarter
- .getInstance((new RuntimeConfigBuilder())
- .defaults(Command.MongoD)
+ .getInstance(Defaults.runtimeConfigFor(Command.MongoD)
.processOutput(processOutput)
.build())
.prepare(mongoConfigConfig);
diff --git a/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonNoFakeTest.java b/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonNoFakeTest.java
index 3f236a2..52ef9c6 100644
--- a/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonNoFakeTest.java
+++ b/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonNoFakeTest.java
@@ -83,19 +83,18 @@ public class MongoHelperSingletonNoFakeTest {
protected static void startEmbedded(int port) throws IOException {
Logger logger = LoggerFactory.getLogger("mongo");
- IMongodConfig mongoConfigConfig = new MongodConfigBuilder()
+ MongodConfig mongoConfigConfig = MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(new Net(port, Network.localhostIsIPv6()))
- .cmdOptions(new MongoCmdOptionsBuilder().enableTextSearch(true).useNoPrealloc(false).build())
- .configServer(false)
+ .cmdOptions(MongoCmdOptions.builder().enableTextSearch(true).useNoPrealloc(false).build())
+ .isConfigServer(false)
.build();
ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.WARN), Processors.logTo(logger,
Slf4jLevel.WARN), Processors.logTo(logger, Slf4jLevel.WARN));
MongodExecutable mongodExecutable = MongodStarter
- .getInstance((new RuntimeConfigBuilder())
- .defaults(Command.MongoD)
+ .getInstance(Defaults.runtimeConfigFor(Command.MongoD)
.processOutput(processOutput)
.build())
.prepare(mongoConfigConfig);
diff --git a/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonTest.java b/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonTest.java
index 872f099..b458b29 100644
--- a/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonTest.java
+++ b/src/test/java/org/onap/aai/cacher/common/MongoHelperSingletonTest.java
@@ -19,12 +19,15 @@
*/
package org.onap.aai.cacher.common;
-import com.github.fakemongo.Fongo;
import com.google.gson.JsonParser;
import com.mongodb.DB;
+import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import org.bson.Document;
import org.json.JSONException;
import org.json.JSONObject;
@@ -36,6 +39,7 @@ import org.onap.aai.cacher.model.CacheEntry;
import org.onap.aai.cacher.model.DBAction;
import org.skyscreamer.jsonassert.JSONAssert;
+import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -54,9 +58,12 @@ public class MongoHelperSingletonTest {
@BeforeClass
public static void setup() {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDatabase = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDatabase = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
@Before
@@ -169,7 +176,6 @@ public class MongoHelperSingletonTest {
.getClass()
.getEnclosingMethod()
.getName();
- setupCollection(collectionName);
MongoCollection<Document> collection = setupCollection(collectionName);
@@ -193,7 +199,6 @@ public class MongoHelperSingletonTest {
.getClass()
.getEnclosingMethod()
.getName();
- setupCollection(collectionName);
MongoCollection<Document> collection = setupCollection(collectionName);
@@ -224,7 +229,6 @@ public class MongoHelperSingletonTest {
.getClass()
.getEnclosingMethod()
.getName();
- setupCollection(collectionName);
MongoCollection<Document> collection = setupCollection(collectionName);
@@ -258,7 +262,6 @@ public class MongoHelperSingletonTest {
.getClass()
.getEnclosingMethod()
.getName();
- setupCollection(collectionName);
MongoCollection<Document> collection = setupCollection(collectionName);
@@ -295,7 +298,6 @@ public class MongoHelperSingletonTest {
.getClass()
.getEnclosingMethod()
.getName();
- setupCollection(collectionName);
MongoCollection<Document> collection = setupCollection(collectionName);
diff --git a/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIDmaapEventProcessorScenariosTest.java b/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIDmaapEventProcessorScenariosTest.java
index c5d39a0..6139fb5 100644
--- a/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIDmaapEventProcessorScenariosTest.java
+++ b/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIDmaapEventProcessorScenariosTest.java
@@ -19,13 +19,15 @@
*/
package org.onap.aai.cacher.dmaap.consumer;
-import com.github.fakemongo.Fongo;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.flapdoodle.embed.mongo.MongodProcess;
import org.apache.commons.io.IOUtils;
import org.bson.Document;
@@ -49,6 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@@ -100,9 +103,12 @@ public class AAIDmaapEventProcessorScenariosTest {
@BeforeClass
public static void setup() throws IOException, InterruptedException {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDb = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDb = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
@AfterClass
diff --git a/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIEventConsumerTest.java b/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIEventConsumerTest.java
index 12d1416..c4a69c9 100644
--- a/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIEventConsumerTest.java
+++ b/src/test/java/org/onap/aai/cacher/dmaap/consumer/AAIEventConsumerTest.java
@@ -20,10 +20,12 @@
package org.onap.aai.cacher.dmaap.consumer;
import com.att.nsa.mr.client.MRConsumer;
-import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.flapdoodle.embed.mongo.MongodProcess;
import org.hamcrest.Matchers;
import org.junit.*;
@@ -41,6 +43,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -48,7 +51,6 @@ import java.util.Properties;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
-//@Ignore
@RunWith(SpringJUnit4ClassRunner.class)
@Configuration
@ContextConfiguration(classes = {InjestionTestComponent.class, AAIEventConsumerTest.class})
@@ -100,9 +102,13 @@ public class AAIEventConsumerTest {
@BeforeClass
public static void setup() throws IOException, InterruptedException {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDb = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDb = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
@Before
diff --git a/src/test/java/org/onap/aai/cacher/injestion/parser/AAIResourcesUriTemplatesTest.java b/src/test/java/org/onap/aai/cacher/injestion/parser/AAIResourcesUriTemplatesTest.java
index d093b6c..8a888dc 100644
--- a/src/test/java/org/onap/aai/cacher/injestion/parser/AAIResourcesUriTemplatesTest.java
+++ b/src/test/java/org/onap/aai/cacher/injestion/parser/AAIResourcesUriTemplatesTest.java
@@ -19,10 +19,12 @@
*/
package org.onap.aai.cacher.injestion.parser;
-import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.flapdoodle.embed.mongo.MongodProcess;
import org.junit.After;
import org.junit.AfterClass;
@@ -38,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.util.*;
import static org.hamcrest.CoreMatchers.is;
@@ -74,9 +77,12 @@ public class AAIResourcesUriTemplatesTest {
@BeforeClass
public static void setup() throws IOException, InterruptedException {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDb = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDb = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
@AfterClass
diff --git a/src/test/java/org/onap/aai/cacher/injestion/parser/PayloadParserServiceTest.java b/src/test/java/org/onap/aai/cacher/injestion/parser/PayloadParserServiceTest.java
index ddac8e3..7ab8da7 100644
--- a/src/test/java/org/onap/aai/cacher/injestion/parser/PayloadParserServiceTest.java
+++ b/src/test/java/org/onap/aai/cacher/injestion/parser/PayloadParserServiceTest.java
@@ -19,20 +19,21 @@
*/
package org.onap.aai.cacher.injestion.parser;
-import com.github.fakemongo.Fongo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
-import de.flapdoodle.embed.mongo.config.IMongodConfig;
-import de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder;
-import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
+import de.flapdoodle.embed.mongo.config.MongoCmdOptions;
+import de.flapdoodle.embed.mongo.config.MongodConfig;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.process.runtime.Network;
@@ -51,6 +52,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@@ -107,17 +109,20 @@ public class PayloadParserServiceTest {
@BeforeClass
public static void setup() throws IOException, InterruptedException {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDb = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDb = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
protected static void startEmbedded(int port) throws IOException {
- IMongodConfig mongoConfigConfig = new MongodConfigBuilder()
+ MongodConfig mongoConfigConfig = MongodConfig.builder()
.version(Version.Main.PRODUCTION)
.net(new Net(port, Network.localhostIsIPv6()))
- .cmdOptions(new MongoCmdOptionsBuilder().verbose(true).build())
- .configServer(false)
+ .cmdOptions(MongoCmdOptions.builder().isVerbose(true).build())
+ .isConfigServer(false)
.build();
MongodExecutable mongodExecutable = MongodStarter.getDefaultInstance().prepare(mongoConfigConfig);
diff --git a/src/test/java/org/onap/aai/cacher/service/helper/CacheHelperServiceScenariosTest.java b/src/test/java/org/onap/aai/cacher/service/helper/CacheHelperServiceScenariosTest.java
index 00beab6..7f2a952 100644
--- a/src/test/java/org/onap/aai/cacher/service/helper/CacheHelperServiceScenariosTest.java
+++ b/src/test/java/org/onap/aai/cacher/service/helper/CacheHelperServiceScenariosTest.java
@@ -19,10 +19,12 @@
*/
package org.onap.aai.cacher.service.helper;
-import com.github.fakemongo.Fongo;
import com.mongodb.DB;
import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import de.flapdoodle.embed.mongo.MongodProcess;
import org.junit.After;
import org.junit.AfterClass;
@@ -44,6 +46,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.ws.rs.core.Response;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -98,7 +101,7 @@ public class CacheHelperServiceScenariosTest {
@Bean
public RestClientHelperService restClientHelperService() {
- return restClientHelperService;
+ return new RestClientHelperService();
}
@Bean
@@ -113,9 +116,12 @@ public class CacheHelperServiceScenariosTest {
@BeforeClass
public static void setup() throws IOException, InterruptedException {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDb = fongo.getDatabase(DB_NAME);
- db = fongo.getDB(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDb = client.getDatabase(DB_NAME);
+ db = client.getDB(DB_NAME);
}
@AfterClass
diff --git a/src/test/java/org/onap/aai/cacher/service/helper/CrudOperationsTest.java b/src/test/java/org/onap/aai/cacher/service/helper/CrudOperationsTest.java
index 1aa1d81..3fce450 100644
--- a/src/test/java/org/onap/aai/cacher/service/helper/CrudOperationsTest.java
+++ b/src/test/java/org/onap/aai/cacher/service/helper/CrudOperationsTest.java
@@ -19,16 +19,21 @@
*/
package org.onap.aai.cacher.service.helper;
-import com.github.fakemongo.Fongo;
+import com.mongodb.MongoClient;
+import com.mongodb.ServerAddress;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.FindOneAndUpdateOptions;
import com.mongodb.client.model.UpdateOptions;
+import de.bwaldvogel.mongo.MongoServer;
+import de.bwaldvogel.mongo.backend.memory.MemoryBackend;
import org.bson.Document;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.net.InetSocketAddress;
+
import static org.junit.Assert.assertEquals;
public class CrudOperationsTest {
@@ -38,8 +43,11 @@ public class CrudOperationsTest {
@BeforeClass
public static void setup() {
- Fongo fongo = new Fongo(DB_NAME);
- mongoDatabase = fongo.getDatabase(DB_NAME);
+ MongoServer mongoServer = new MongoServer(new MemoryBackend());
+ InetSocketAddress serverAddress = mongoServer.bind();
+
+ MongoClient client = new MongoClient(new ServerAddress(serverAddress));
+ mongoDatabase = client.getDatabase(DB_NAME);
}
@Test