diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2021-07-26 12:42:00 +0530 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-07-28 16:08:00 +0000 |
commit | 016536791b95df23811dabd063010f0561526163 (patch) | |
tree | dc9af75cdad070fa803b6ea8799cfa38244a17f0 /sdnr/wt/data-provider/provider/src/test/java | |
parent | d70d7624795a9305eef1f0a6d3842d47ecd27160 (diff) |
Support for MariaDB
Support for MariaDB
Issue-ID: CCSDK-3384
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: Ic93ad33257a091f2cd208cdf02d1d7400c256bf0
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test/java')
15 files changed, 207 insertions, 35 deletions
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java index 48e512ad9..eb4ec3296 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java @@ -85,7 +85,7 @@ public class TestAbout { when(response.getOutputStream()).thenReturn(printOut); servlet.doGet(request, response); verify(response).setStatus(200); - verify(response).setContentType("text/plain"); + verify(response).setContentType("text/markdown"); System.out.println(printOut.getStringWriter().getBuffer().toString()); assertTrue(printOut.getStringWriter().getBuffer().length() > 0); } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java index 5a8c549d8..c407859d5 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -39,8 +39,9 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.HtUserdataManagerImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; @@ -125,7 +126,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestCRUDforDatabase { - private static ElasticSearchDataProvider dbProvider; + private static DatabaseDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; @BeforeClass diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java index 9a96986c0..8c62ec9d5 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java @@ -31,7 +31,7 @@ import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.EsConfig; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java index d06486550..dd285754a 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.exception.ConfigurationException; import org.onap.ccsdk.features.sdnr.wt.common.util.ResourceFileLoader; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.EsConfig; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsConfig; public class TestConfiguration { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java index b83034d90..dc5e049fd 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -37,8 +37,9 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; @@ -70,7 +71,7 @@ import org.opendaylight.yangtools.yang.common.Uint32; * */ public class TestEventService { - private static ElasticSearchDataProvider dbProvider; + private static DatabaseDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; private static HtDatabaseEventsService service = null; @@ -154,7 +155,7 @@ public class TestEventService { service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); TestCRUDforDatabase.trySleep(100); now = new Date(); - int numOlds = service.getNumberOfOldObjects(now); + long numOlds = service.getNumberOfOldObjects(now); assertEquals(5, numOlds); TestCRUDforDatabase.trySleep(100); service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); @@ -205,11 +206,12 @@ public class TestEventService { clearDbEntity(Entity.NetworkelementConnection); List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections(); assertEquals(0, nes.size()); - service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); - service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2); + service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown, null), NODEID); + service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown, "old"), NODEID); + service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN, "old"), NODEID2); nes = service.getNetworkElementConnections(); assertEquals(2, nes.size()); - service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless), + service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless,"old"), NODEID); nes = service.getNetworkElementConnections(); assertEquals(2, nes.size()); @@ -278,12 +280,13 @@ public class TestEventService { /** * @param devType + * @param mountMethod * @param nodename3 * @return */ - private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { + private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType, String mountMethod) { return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host") - .setPort(YangHelper2.getLongOrUint32(1234L)).setCoreModelCapability("123") + .setPort(YangHelper2.getLongOrUint32(1234L)).setCoreModelCapability("123")//.setMountMethod(mountMethod) .setStatus(ConnectionLogStatus.Connected).setDeviceType(devType).setIsRequired(true).build(); } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java index 68d367668..8a4e3e202 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java @@ -29,7 +29,7 @@ import java.util.List; import org.junit.Test; import org.mockito.Mockito; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryByFilter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SortOrder; @@ -66,7 +66,7 @@ public class TestFilterConversion extends Mockito { List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); when(input.getFilter()).thenReturn(YangHelper2.getListOrMap(FilterKey.class, filters)); try { - new QueryByFilter(input).getSearchRequestByFilter("test1", "test2", "test3", "test4"); + new QueryByFilter(input).getSearchRequestByFilter("test1", "test2", "test3", "test4", false); fail(); } catch (IllegalArgumentException e) { // fails if type not correct diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java index 16dfa0ec6..3c983e7a7 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -81,7 +81,6 @@ public class TestImplementation { } impl.setStatus(StatusKey.CLUSTER_SIZE, "3"); - impl.setReadyStatus(true); try { impl.close(); } catch (Exception e) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java index ed8eac949..ce1bd78fa 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInventoryConsistency.java @@ -28,10 +28,10 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory; @@ -39,16 +39,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestInventoryConsistency { private static final String TEST1NODEID = "sim1"; - private static String resourceDirectoryPath = "/" + TestTree.class.getSimpleName() + "/"; - private static ElasticSearchDataProvider dbProvider; - private static HtDatabaseClient dbRawProvider; + private static DatabaseDataProvider dbProvider; @BeforeClass public static void init() throws Exception { HostInfo[] hosts = HostInfoForTest.get(); dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = HtDatabaseClient.getClient(hosts); } @Test diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java index b9516b363..e85ed8cdd 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java @@ -33,7 +33,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; @@ -45,7 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro */ public class TestMaintenanceServiceData { - private static ElasticSearchDataProvider dbProvider; + private static DatabaseDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; private static HtDatabaseMaintenance service = null; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java index 5b4bc3e0f..408f6a636 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -32,8 +32,9 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.MediatorServerDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerOutputBuilder; @@ -43,7 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro * @author Michael Dürre */ public class TestMediatorServerService { - private static ElasticSearchDataProvider dbProvider; + private static DatabaseDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; private static MediatorServerDataProvider service = null; @@ -54,7 +55,7 @@ public class TestMediatorServerService { dbProvider = new ElasticSearchDataProvider(hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); dbRawProvider = HtDatabaseClient.getClient(hosts); - service = new MediatorServerDataProvider(hosts); + service = new MediatorServerDataProvider(dbProvider.getHtDatabaseMediatorServer()); } @Test diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java index ad525b910..4a36262fd 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java @@ -30,7 +30,7 @@ import org.json.JSONObject; import org.junit.Test; import org.mockito.Mockito; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.rpctypehelper.QueryByFilter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.rpctypehelper.QueryByFilter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java index 28f7d49fe..29f35560e 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java @@ -35,7 +35,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest; import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.EntityWithTree; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; @@ -46,7 +47,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestTree { private static String resourceDirectoryPath = "/" + TestTree.class.getSimpleName() + "/"; - private static ElasticSearchDataProvider dbProvider; + private static DatabaseDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; @BeforeClass diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java index fd397840e..3fcbdb84c 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java @@ -30,7 +30,7 @@ import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.HtUserdataManagerImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; public class TestUserdata { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java index 524659e99..611533ba1 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java @@ -37,7 +37,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.CreateIndexRequest; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexRequest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.EsDataObjectReaderWriter2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java new file mode 100644 index 000000000..276bcf4a1 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/util/MariaDBTestBase.java @@ -0,0 +1,169 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.dataprovider.test.util; + +import static org.junit.Assert.fail; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBClient; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlDBDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper.UnableToMapClassException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GuicutthroughEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MaintenanceEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MediatorServerEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata15mEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata24hEntity; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; + +public class MariaDBTestBase { + + private final SqlDBDataProvider dbProvider; + private final DB db; + private static final Map<String, String> envDefaultValues = initEnvDefaultValues(); + + public MariaDBTestBase() throws ManagedProcessException { + this(new Random().nextInt(1000) + 50000); + } + + private static Map<String, String> initEnvDefaultValues() { + Map<String, String> defaults = new HashMap<>(); + defaults.put("SDNRDBHOST", "localhost"); + defaults.put("SDNRDBDATABASE", "test"); + + return defaults; + } + + public MariaDBTestBase(String host, int port) { + EnvGetter env = Section.getEnvGetter(); + envDefaultValues.put("SDNRDBPORT", String.valueOf(port)); + envDefaultValues.put("SDNRDBHOST", host); + envDefaultValues.put("SDNRDBDATABASE", "sdnrdb"); + envDefaultValues.put("SDNRDBUSERNAME", "sdnrdb"); + envDefaultValues.put("SDNRDBPASSWORD", "sdnrdb"); + Section.setEnvGetter((envname) -> { + return envDefaultValues.getOrDefault(envname, env.getenv(envname)); + }); + SqlDBConfig config = new SqlDBConfig(new ConfigurationFileRepresentation("test.properties")); + this.db = null; + this.dbProvider = new SqlDBDataProvider(config); + testCreateTable(this.dbProvider.getDBService()); + } + + public MariaDBTestBase(int port) throws ManagedProcessException { + EnvGetter env = Section.getEnvGetter(); + envDefaultValues.put("SDNRDBPORT", String.valueOf(port)); + Section.setEnvGetter((envname) -> { + return envDefaultValues.getOrDefault(envname, env.getenv(envname)); + }); + SqlDBConfig config = new SqlDBConfig(new ConfigurationFileRepresentation("test.properties")); + //start db server + this.db = startDatabase(port); + //create db with name sdnrdb + this.dbProvider = new SqlDBDataProvider(config); + testCreateTable(this.dbProvider.getDBService()); + } + + public void close() throws ManagedProcessException { + if (db != null) { + this.db.stop(); + } + + } + + public SqlDBDataProvider getDbProvider() { + return dbProvider; + } + + public DB getDb() { + return db; + } + + private static DB startDatabase(int port) throws ManagedProcessException { + // Start MariaDB4j database + DBConfigurationBuilder dbconfig = DBConfigurationBuilder.newBuilder(); + dbconfig.setPort(port); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(dbconfig.build()); + db.start(); + return db; + } + public static void testCreateTable(SqlDBClient dbService) { + createTableOdl(dbService); + createTable(dbService, ConnectionlogEntity.class, Entity.Connectionlog, true); + createTable(dbService, EventlogEntity.class, Entity.Eventlog, true); + createTable(dbService, FaultcurrentEntity.class, Entity.Faultcurrent, false); + createTable(dbService, FaultlogEntity.class, Entity.Faultlog, true); + createTable(dbService, GuicutthroughEntity.class, Entity.Guicutthrough, true); + createTable(dbService, Pmdata15mEntity.class, Entity.Historicalperformance15min, false); + createTable(dbService, Pmdata24hEntity.class, Entity.Historicalperformance24h, false); + createTable(dbService, InventoryEntity.class, Entity.Inventoryequipment, false); + createTable(dbService, MaintenanceEntity.class, Entity.Maintenancemode, false); + createTable(dbService, MediatorServerEntity.class, Entity.MediatorServer, true); + createTable(dbService, NetworkElementConnectionEntity.class, Entity.NetworkelementConnection, false); + } + public static boolean createTableOdl(SqlDBClient dbService) { + String createStatement = null; + createStatement = SqlDBMapper.createTableOdl(); + System.out.println(createStatement); + try { + return dbService.write(createStatement); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } + return false; + } + + public static boolean createTable(SqlDBClient dbService, Class<?> cls, Entity entity, boolean autoIndex) { + String createStatement = null; + try { + createStatement = SqlDBMapper.createTable(cls, entity, "", autoIndex); + } catch (UnableToMapClassException e) { + fail(e.getMessage()); + } + System.out.println(createStatement); + try { + return dbService.write(createStatement); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } + return false; + } +} |