diff options
author | 2020-02-06 12:57:23 +0100 | |
---|---|---|
committer | 2020-02-07 16:41:48 +0000 | |
commit | f6f3b57be8e57ffc6790d139b0b7f168b8cc69e6 (patch) | |
tree | d510d50c0f651e5b7f853ec6247f57a1a7f2b432 /sdnr/wt/data-provider/provider/src/test/java/org | |
parent | 561aa2a8ef7bd222d274aea065929920aedd0723 (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/test/java/org')
7 files changed, 617 insertions, 41 deletions
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 748ad51c6..d898644c9 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 @@ -114,7 +114,7 @@ public class TestCRUDforDatabase { private static ElasticSearchDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; - private static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer + public static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")) }; @BeforeClass @@ -125,7 +125,7 @@ public class TestCRUDforDatabase { dbRawProvider = new HtDatabaseClient(hosts); } - private static void trySleep(long ms) { + public static void trySleep(long ms) { try { Thread.sleep(ms); } catch (Exception e) { @@ -133,7 +133,7 @@ public class TestCRUDforDatabase { } } - private static void trySleep() { + public static void trySleep() { trySleep(0); } @@ -1183,8 +1183,8 @@ public class TestCRUDforDatabase { // == UPDATE ============================== - String shouldbeEmpty = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); - assertEquals("",shouldbeEmpty); + boolean success = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); + assertTrue("update dbentry not succeeded",success); try { readltpResult = dbProvider.readPmdata24hLtpList(readLtp); } catch (Exception e) { 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 new file mode 100644 index 000000000..850d80e1a --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -0,0 +1,316 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Date; +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.SearchResult; +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.DeleteByQueryRequest; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.PmdataEntityBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType; + +/** + * @author Michael Dürre + * + */ +public class TestEventService { + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HtDatabaseEventsService service = null; + + private static final String NODEID = "node1"; + private static final String NODEID2 = "node2"; + private static final String OBJECTREFID1 = "objid1"; + private static final String OBJECTREFID2 = "objid2"; + + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + + try { + service = new HtDatabaseEventsService(dbRawProvider, dbProvider); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + + @Test + public void testClearFaultsCurrent() { + + service.clearFaultsCurrentOfNode(NODEID); + service.clearFaultsCurrentOfNode(NODEID2); + + List<String> nodeIds = service.getAllNodesWithCurrentAlarms(); + if (nodeIds.size() > 0) { + for (String nodeId : nodeIds) { + service.clearFaultsCurrentOfNode(nodeId); + } + } + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abc", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID2, OBJECTREFID2, "abcde", SeverityType.Major)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.clearFaultsCurrentOfNodeWithObjectId(NODEID, OBJECTREFID1); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.NonAlarmed)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 1); + } + + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity) { + return createFault(nodeId, objectRefId, problem, severity, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } + + /** + * @param nODENAME + * @param problem + * @param ts + * @param severity + * @return + */ + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity, DateAndTime ts) { + return new FaultcurrentBuilder().setNodeId(nodeId).setObjectId(objectRefId).setTimestamp(ts) + .setSeverity(severity).setProblem(problem).build(); + } + + @Test + public void testIndexClean() { + Date now = new Date(); + service.doIndexClean(now); + clearDbEntity(Entity.Eventlog); + clearDbEntity(Entity.Faultlog); + TestCRUDforDatabase.trySleep(1000); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "abc", 1)); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "avasvas", 2)); + + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 1)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 2)); + service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); + TestCRUDforDatabase.trySleep(100); + now = new Date(); + int numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + TestCRUDforDatabase.trySleep(100); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 5)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 6)); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + now = new Date(); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(8, numOlds); + service.doIndexClean(now); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(0, numOlds); + + } + + @Test + public void testPm() { + final String IFNAME1 = "if1"; + final String SCNID1 = "scn1"; + List<PmdataEntity> list = Arrays.asList(createPmData(NODEID, IFNAME1, SCNID1), + createPmData(NODEID, IFNAME1, SCNID1), createPmData(NODEID, IFNAME1, SCNID1), + createPmData(NODEID, IFNAME1, SCNID1) + + ); + service.doWritePerformanceData(list); + } + + /** + * @param ifname + * @param ifUuid + * @param scannerId + * @param nodename3 + * @return + */ + private static PmdataEntity createPmData(String nodeId, String ifUuid, String scannerId) { + return new PmdataEntityBuilder().setNodeName(nodeId).setGranularityPeriod(GranularityPeriodType.Period15Min) + .setUuidInterface(ifUuid).setScannerId(scannerId).setLayerProtocolName("NETCONF") + .setPerformanceData(null).setSuspectIntervalFlag(true) + .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).build(); + } + + @Test + public void testNeConnection() { + service.removeNetworkConnection(NODEID); + service.removeNetworkConnection(NODEID2); + + 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); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless), + NODEID); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + boolean found = false; + for (NetworkElementConnectionEntity ne : nes) { + if (NODEID.equals(ne.getNodeId()) && ne.getDeviceType() == NetworkElementDeviceType.Wireless) { + found = true; + } + } + assertTrue(found); + + } + + @Test + public void testConnectionLog() { + clearDbEntity(Entity.Connectionlog); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + assertEquals(2, getDbEntityEntries(Entity.Connectionlog).getTotal()); + } + + /** + * @param nodeId + * @param status + * @return + */ + private static ConnectionlogEntity createConnectionLog(String nodeId, ConnectionLogStatus status) { + return new ConnectionlogBuilder().setNodeId(nodeId) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setStatus(status).build(); + } + + @Test + public void testInventory() { + clearDbEntity(Entity.Inventoryequipment); + service.writeInventory(createEquipment(NODEID, "uuid1")); + service.writeInventory(createEquipment(NODEID, "uuid2")); + service.writeInventory(createEquipment(NODEID2, "uuid3")); + service.writeInventory(createEquipment(NODEID2, "uuid4")); + service.writeInventory(createEquipment(NODEID2, "uuid5")); + assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal()); + } + + private static SearchResult<SearchHit> getDbEntityEntries(Entity entity) { + return dbRawProvider.doReadAllJsonData(entity.getName()); + } + + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } + + /** + * @param nodeId + * @param uuid + * @return + */ + private Inventory createEquipment(String nodeId, String uuid) { + return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc") + .setManufacturerName("manu").setUuid(uuid).build(); + } + + /** + * @param devType + * @param nodename3 + * @return + */ + private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { + return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(1234L) + .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType) + .setIsRequired(true).build(); + } + + /** + * @param nodeId + * @param objectId + * @param problem + * @param severity + * @param counter + * @return + */ + private static FaultlogEntity createFaultLog(String nodeId, String objectId, String problem, SeverityType severity, + int counter) { + return new FaultlogBuilder().setNodeId(nodeId).setObjectId(objectId).setProblem(problem).setSeverity(severity) + .setCounter(counter).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) + .setSourceType(SourceType.Netconf).build(); + } + + /** + * @param nodeId + * @param objectId + * @param attributeName + * @param newValue + * @param counter + * @return + */ + private static EventlogEntity createEventLog(String nodeId, String objectId, String attributeName, String newValue, + int counter) { + return new EventlogBuilder().setNodeId(nodeId).setObjectId(objectId).setAttributeName(attributeName) + .setNewValue(newValue).setCounter(counter) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setSourceType(SourceType.Netconf) + .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 94381b6a3..5ce8fcc0b 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 @@ -17,23 +17,47 @@ ******************************************************************************/ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Arrays; import java.util.List; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.QueryByFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SortOrder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Filter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.Sortorder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.SortorderBuilder; public class TestFilterConversion { private static final String PROPERTY = "node-id"; + private static final String PROPERTY2 = "_id"; + private static final String PROPERTY3 = "timestamp"; @Test public void testQuestionMark() { - List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); - QueryBuilder query = QueryByFilter.fromFilter(filters ); + List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); + QueryBuilder query = QueryByFilter.fromFilter(filters); + System.out.println(query.toJSON()); + assertTrue(query.toJSON().contains("{1,1}")); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY)); + assertNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY2).setFiltervalue("abc").build()); + query = QueryByFilter.fromFilter(filters); System.out.println(query.toJSON()); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY3).setFiltervalue("<2019-06-13T15:00:12.0Z").build()); + query = QueryByFilter.fromFilter(filters); + List<Sortorder> sortorder = Arrays + .asList(new SortorderBuilder().setProperty(PROPERTY).setSortorder(SortOrder.Ascending).build()); + QueryByFilter.setSortOrder(query, sortorder); + assertNotNull(QueryByFilter.getSortOrder(sortorder, PROPERTY)); } } 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 new file mode 100644 index 000000000..eae301a34 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 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; + +import static org.junit.Assert.fail; + +import java.util.Set; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DataProviderService; +import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.RpcService; + +import net.bytebuddy.implementation.bytecode.StackSize; + +/** + * @author Michael Dürre + * + */ +public class TestImplementation { + + @Test + public void test() { + DataProviderImpl impl = new DataProviderImpl(); + impl.setRpcProviderService(new RpcProviderService() { + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation, Set<InstanceIdentifier<?>> paths) { + // TODO Auto-generated method stub + return null; + } + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation) { + // TODO Auto-generated method stub + return null; + } + }); + impl.setMediatorServerServlet(new MsServlet()); + impl.setAboutServlet(new AboutHttpServlet()); + try { + impl.init(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to init impl: "+e.getMessage()); + } + + impl.setStatus(StatusKey.CLUSTER_SIZE, "3"); + impl.setReadyStatus(true); + try { + impl.close(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to close impl: "+e.getMessage()); + } + } + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java deleted file mode 100644 index 633912579..000000000 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 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; - -import static org.junit.Assert.*; - -import org.junit.Test; - -/** - * - Handling of inital values for Maintenance mode. - */ -public class TestInitalMaintenanceObjectInDatabase { - - //@Test - public void test() { - fail("Not yet implemented"); - } - -} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java new file mode 100644 index 000000000..bd91219c8 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceService.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 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; + +import static org.junit.Assert.*; + +import java.io.IOException; +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.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.HtDatabaseEventsService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtDatabaseMaintenanceService; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity; + +/** + * - Handling of inital values for Maintenance mode. + */ +public class TestMaintenanceService { + + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HtDatabaseMaintenance service = null; + + private static final String NODEID = "node1"; + private static final String NODEID2 = "node2"; + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + service = dbProvider.getHtDatabaseMaintenance(); + } + @Test + public void test() { + clearDbEntity(Entity.Maintenancemode); + MaintenanceEntity obj = service.createIfNotExists(NODEID); + assertNotNull(obj); + obj = service.createIfNotExists(NODEID2); + assertNotNull(obj); + obj = service.getMaintenance(NODEID); + assertNotNull(obj); + List<MaintenanceEntity> list = service.getAll(); + assertEquals(2,list.size()); + service.deleteIfNotRequired(NODEID); + obj = service.getMaintenance(NODEID); + assertNull(obj); + + + obj = service.setMaintenance(createMaintenance(NODEID,true)); + + + } + /** + * @param nodeId + * @param active + * @return + */ + private static MaintenanceEntity createMaintenance(String nodeId, Boolean active) { + return new MaintenanceBuilder().setNodeId(nodeId).setActive(active).setProblem("problem").setObjectIdRef("idref").build(); + } + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } + +} 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 new file mode 100644 index 000000000..20c0da596 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.io.IOException; +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.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.model.HtDatabaseMaintenance; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity; + +/** + * @author Michael Dürre + * + */ +public class TestMediatorServerService { + private static final String SERVERID = null; + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static MediatorServerDataProvider service = null; + + + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts); + + + } + @Test + public void test() { + clearDbEntity(Entity.MediatorServer); + System.out.println(service.triggerReloadSync()); + String dbServerId="abc"; + String host = service.getHostUrl(dbServerId); + assertNull(host); + final String NAME="ms1"; + final String HOST = "http://10.20.30.40:7070"; + CreateMediatorServerOutputBuilder output = null; + try { + output = dbProvider.createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build()); + } catch (IOException e) { + e.printStackTrace(); + fail("unable to create ms entry: "+e.getMessage()); + } + System.out.println(service.triggerReloadSync()); + host = service.getHostUrl(output.getId()); + assertEquals(HOST, host); + + } + + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } +} |