summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/provider/src/main
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-02-06 12:57:23 +0100
committerKAPIL SINGAL <ks220y@att.com>2020-02-07 16:41:48 +0000
commitf6f3b57be8e57ffc6790d139b0b7f168b8cc69e6 (patch)
treed510d50c0f651e5b7f853ec6247f57a1a7f2b432 /sdnr/wt/data-provider/provider/src/main
parent561aa2a8ef7bd222d274aea065929920aedd0723 (diff)
improve code coverage
more unit tests for common and data-provider Issue-ID: SDNC-1063 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: Id99cb3e300b9649b77e0900347fbefae8d55cd87 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/main')
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java2
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java31
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java74
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java4
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java4
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java20
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java2
7 files changed, 75 insertions, 62 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java
index 63d92b64d..1192950e6 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtDatabaseEventsService.java
@@ -371,7 +371,7 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid
* @return QueryBuilder for older elements related to timestamp
*/
private static QueryBuilder getQueryForTimeStamp(String netconfTimeStamp) {
- return new RangeQueryBuilder("event.timeStamp").lte(netconfTimeStamp);
+ return new RangeQueryBuilder("timestamp").lte(netconfTimeStamp);
}
}
private static class EsFaultLogDevicemanager {
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
index bc61e81e5..9e576857b 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/MediatorServerDataProvider.java
@@ -61,32 +61,35 @@ public class MediatorServerDataProvider implements AutoCloseable {
@Override
public void run() {
isRunning = true;
- SearchResult<Data> result = MediatorServerDataProvider.this.mediatorserverRW.doReadAll();
- List<Data> data = result.getHits();
- for (Data item : data) {
- MediatorServerDataProvider.this.entries.put(item.getId(), item);
- }
+ runIt();
isRunning = false;
}
};
+ private void runIt() {
+ SearchResult<Data> result = MediatorServerDataProvider.this.mediatorserverRW.doReadAll();
+ List<Data> data = result.getHits();
+ for (Data item : data) {
+ MediatorServerDataProvider.this.entries.put(item.getId(), item);
+ }
+ }
+
+ /**
+ *
+ * @param dbServerId
+ * @return url or null if not exists
+ */
public String getHostUrl(String dbServerId) {
Data info = this.entries.getOrDefault(dbServerId, null);
return info == null ? null : info.getUrl();
}
public boolean triggerReloadSync() {
- new Thread(onTick).start();
- int i = 20;
- while (isRunning && i-- > 0) {
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ if (!isRunning) {
+ runIt();
}
- return i > 0;
+ return true;
}
@Override
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java
index 2b3ebd86e..fbdc9d825 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/SystemInfo.java
@@ -163,43 +163,43 @@ public class SystemInfo {
printValue(sb, "Garbage collector", maxNameLen, val);
}
- if (showMemoryPools) {
- List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
- sb.append("Memory Pools\n");
- printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size()));
- String spaces4 = " ";
- for (MemoryPoolMXBean pool : memoryPools) {
- String name = pool.getName();
- MemoryType type = pool.getType();
- printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name);
-
- // PeakUsage/CurrentUsage
- MemoryUsage peakUsage = pool.getPeakUsage();
- MemoryUsage usage = pool.getUsage();
-
- if (usage != null && peakUsage != null) {
- long init = peakUsage.getInit();
- long used = peakUsage.getUsed();
- long committed = peakUsage.getCommitted();
- long max = peakUsage.getMax();
- sb.append(spaces4 + spaces4 + "Peak Usage\n");
- printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
- printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
- printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
- printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
-
- init = usage.getInit();
- used = usage.getUsed();
- committed = usage.getCommitted();
- max = usage.getMax();
- sb.append(spaces4 + spaces4 + "Current Usage\n");
- printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
- printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
- printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
- printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
- }
- }
- }
+// if (showMemoryPools) {
+// List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
+// sb.append("Memory Pools\n");
+// printValue(sb, "Total Memory Pools", maxNameLen, printLong(memoryPools.size()));
+// String spaces4 = " ";
+// for (MemoryPoolMXBean pool : memoryPools) {
+// String name = pool.getName();
+// MemoryType type = pool.getType();
+// printValue(sb, spaces4 + "Pool (" + type + ")", maxNameLen, name);
+//
+// // PeakUsage/CurrentUsage
+// MemoryUsage peakUsage = pool.getPeakUsage();
+// MemoryUsage usage = pool.getUsage();
+//
+// if (usage != null && peakUsage != null) {
+// long init = peakUsage.getInit();
+// long used = peakUsage.getUsed();
+// long committed = peakUsage.getCommitted();
+// long max = peakUsage.getMax();
+// sb.append(spaces4 + spaces4 + "Peak Usage\n");
+// printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
+//
+// init = usage.getInit();
+// used = usage.getUsed();
+// committed = usage.getCommitted();
+// max = usage.getMax();
+// sb.append(spaces4 + spaces4 + "Current Usage\n");
+// printValue(sb, spaces4 + spaces4 + spaces4 + "init", maxNameLen, printLong(init));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "used", maxNameLen, printLong(used));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "committed", maxNameLen, printLong(committed));
+// printValue(sb, spaces4 + spaces4 + spaces4 + "max", maxNameLen, printLong(max));
+// }
+// }
+// }
sb.append("Classes\n");
printValue(sb, "Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java
index b119b80d4..3fd74b09d 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter.java
@@ -190,7 +190,7 @@ public class EsDataObjectReaderWriter<T extends DataObject> {
* @param esId
* @return String with esId or null
*/
- public @Nullable <S extends DataObject> String update(S object, QueryBuilder query) {
+ public @Nullable <S extends DataObject> boolean update(S object, QueryBuilder query) {
if (writeInterfaceClazz.isInstance(object)) {
try {
String json = yangtoolsMapper.writeValueAsString(object);
@@ -202,7 +202,7 @@ public class EsDataObjectReaderWriter<T extends DataObject> {
LOG.error("Type {} does not provide interface {}", object!=null?object.getClass().getName():"null",
writeInterfaceClazz.getName());
}
- return null;
+ return false;
}
/**
* Write/ update partial child object to database with specific id Write if not
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
index d097d8284..d3d9dbf25 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
@@ -204,7 +204,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> {
* @param query for write of specific attributes
* @return json string with new Object
*/
- public @Nullable <S extends DataObject> String update(S object, QueryBuilder query) {
+ public @Nullable <S extends DataObject> boolean update(S object, QueryBuilder query) {
if (object != null && writeInterfaceClazz.isInstance(object)) {
try {
String json = yangtoolsMapper.writeValueAsString(object);
@@ -216,7 +216,7 @@ public class EsDataObjectReaderWriter2<T extends DataObject> {
LOG.error("Type {} does not provide interface {}", object!=null?object.getClass().getName():"null",
writeInterfaceClazz.getName());
}
- return null;
+ return false;
}
/**
* Write/ update partial child object to database with specific id Write if not
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java
index cdcbb4912..6a42d0f21 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/MsServlet.java
@@ -39,9 +39,9 @@ public class MsServlet extends BaseServlet {
private static final long serialVersionUID = -5361461082028405171L;
private static final String OFFLINE_RESPONSE_MESSAGE = "MediatorServer interface is offline";
private static boolean trustAll = false;
- private MediatorServerDataProvider entryProvider;
+ private static MediatorServerDataProvider entryProvider;
public MsServlet() {
- super(false);
+ super();
}
@Override
@@ -59,7 +59,7 @@ public class MsServlet extends BaseServlet {
public void triggerReloadDatabaseEntries() {
LOG.debug("external reload triggered");
- this.entryProvider.triggerReloadSync();
+ entryProvider.triggerReloadSync();
}
@Override
@@ -85,7 +85,7 @@ public class MsServlet extends BaseServlet {
}
protected String getBaseUrl(String dbServerId) {
- return this.entryProvider.getHostUrl(dbServerId);
+ return entryProvider.getHostUrl(dbServerId);
}
@Override
protected boolean doTrustAll() {
@@ -97,6 +97,16 @@ public class MsServlet extends BaseServlet {
}
public void setDataProvider(MediatorServerDataProvider mediatorServerDataProvider) {
- this.entryProvider = mediatorServerDataProvider;
+ entryProvider = mediatorServerDataProvider;
+ }
+
+ @Override
+ protected boolean trustInsecure() {
+ return trustAll;
+ }
+
+ @Override
+ protected boolean isCorsEnabled() {
+ return false;
}
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java
index fc9ae5085..a846cd8f3 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/EsConfig.java
@@ -98,7 +98,7 @@ public class EsConfig implements Configuration, IEsConfig {
public boolean hasBasicAuthCredentials() {
return this.getBasicAuthUsername()!=null && this.getBasicAuthPassword()!=null &&
- this.getBasicAuthUsername()!="" && this.getBasicAuthPassword()!="" ;
+ !this.getBasicAuthUsername().isEmpty() && !this.getBasicAuthPassword().isEmpty() ;
}
public String getBasicAuthUsername() {
return this.configuration.getProperty(SECTION_MARKER_ES, PROPERTY_KEY_AUTH_USERNAME);