diff options
author | herbert <herbert.eiselt@highstreet-technologies.com> | 2020-01-30 10:15:11 +0100 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2020-01-31 19:42:37 +0000 |
commit | d77d01bae41b5c8331a6de6eff1a64e08cd9e279 (patch) | |
tree | b0863c9c34916a0fab99d044ad9f8925597bfbc3 /sdnr/wt/data-provider/provider/src/test | |
parent | 913eea4f5e7bdb32f9fa42767ccbc9b1cf04f5ef (diff) |
SDN-R add updated app
add updated data-provider
Issue-ID: SDNC-1026
Signed-off-by: herbert <herbert.eiselt@highstreet-technologies.com>
Change-Id: I641f8144955fcfb196d0cb19d57452c1d1a69a92
Signed-off-by: herbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test')
18 files changed, 3063 insertions, 0 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 new file mode 100644 index 000000000..01dc8fcaf --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * ============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 org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.AboutHttpServlet; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.file.Files; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TestAbout { + + private static final String REPO_MDSAL_DIR = "system/org/opendaylight/mdsal/mdsal-binding-api/3.0.9/"; + private static final String REPO_YANGTOOLS_DIR = "system/org/opendaylight/yangtools/odl-yangtools-common/2.1.11"; + @BeforeClass + public static void before() throws IOException { + //create temporary odl folder structure in tmp + Files.createDirectories(new File(REPO_MDSAL_DIR).toPath() ); + Files.createDirectories(new File(REPO_YANGTOOLS_DIR).toPath() ); + } + @AfterClass + public static void after() throws IOException { + //delete created dirs + delete(new File("system/")); + } + private static void delete(File file) throws IOException { + + for (File childFile : file.listFiles()) { + + if (childFile.isDirectory()) { + delete(childFile); + } else { + if (!childFile.delete()) { + throw new IOException(); + } + } + } + + if (!file.delete()) { + throw new IOException(); + } + } + @Test + public void testReadmeRequest() throws IOException, ServletException { + AboutHelperServlet servlet =new AboutHelperServlet(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + when(request.getRequestURI()).thenReturn("/about"); + StringWriter out = new StringWriter(); + ServletOutputStream printOut = new ServletOutputStream() { + + @Override + public void write(int arg0) throws IOException { + out.write(arg0); + } + }; + when(response.getOutputStream()).thenReturn(printOut); + servlet.doGet(request,response); + verify(response).setStatus(200); + verify(response).setContentType("text/plain"); + System.out.println(out.getBuffer().toString()); + assertTrue(out.getBuffer().length()>0); + } + + @Test + public void testReadmeResourceRequest() throws IOException, ServletException { + AboutHelperServlet servlet =new AboutHelperServlet(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + when(request.getRequestURI()).thenReturn("/about/test.bmp"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ServletOutputStream printOut = new ServletOutputStream() { + + @Override + public void write(int arg0) throws IOException { + out.write(arg0); + } + }; + when(response.getOutputStream()).thenReturn(printOut); + servlet.doGet(request,response); + verify(response).setStatus(200); + verify(response).setContentType("image/bmp"); + assertTrue(out.size()>0); + } + + + + private class AboutHelperServlet extends AboutHttpServlet{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + super.doGet(req, resp); + } + + } +} 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 new file mode 100644 index 000000000..748ad51c6 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -0,0 +1,1450 @@ +/******************************************************************************* + * ============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.math.BigInteger; +import java.util.Arrays; +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.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.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.CreateMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMaintenanceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInput; +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.CreateNetworkElementConnectionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateNetworkElementConnectionInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateNetworkElementConnectionOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteMaintenanceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteMediatorServerInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteMediatorServerInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteNetworkElementConnectionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.DeleteNetworkElementConnectionInputBuilder; +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.GranularityPeriodType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadConnectionlogListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadConnectionlogListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadConnectionlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadEventlogListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadEventlogListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadEventlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultcurrentListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultcurrentListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultcurrentListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultlogListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultlogListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadFaultlogListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadInventoryListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadInventoryListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadInventoryListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMaintenanceListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMaintenanceListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMaintenanceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMediatorServerListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMediatorServerListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadMediatorServerListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadNetworkElementConnectionListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadNetworkElementConnectionListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadNetworkElementConnectionListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mDeviceListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mDeviceListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mDeviceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mLtpListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mLtpListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mLtpListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hDeviceListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hDeviceListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hDeviceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hLtpListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hLtpListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata24hLtpListOutputBuilder; +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.UpdateMaintenanceInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateMaintenanceInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateMaintenanceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateMediatorServerInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateMediatorServerInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateMediatorServerOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.UpdateNetworkElementConnectionOutputBuilder; +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.Pagination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.PaginationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data; + +public class TestCRUDforDatabase { + + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer + .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")) }; + + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(hosts); + } + + private static void trySleep(long ms) { + try { + Thread.sleep(ms); + } catch (Exception e) { + Thread.currentThread().interrupt(); + } + } + + private static void trySleep() { + trySleep(0); + } + + @Test + public void testStatus() throws IOException { + + //== CLEAR AND CREATE ================================ + clearAndCreatefaultEntity("1", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.Critical); + createFaultEntity("Lorem Ipsum", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.Major); + createFaultEntity("3", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.Minor); + createFaultEntity("4", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.Warning); + + //== READ ================================ + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.status.output.Data> readOutput = dbProvider.readStatus().getData(); + System.out.println(readOutput); + + assertEquals(1,readOutput.get(0).getFaults().getMajors().intValue()); + assertEquals(1,readOutput.get(0).getFaults().getMinors().intValue()); + assertEquals(1,readOutput.get(0).getFaults().getWarnings().intValue()); + assertEquals(1,readOutput.get(0).getFaults().getCriticals().intValue()); + + //== DELETE ================================ + + System.out.println("try to delete entries"); + try { + dbRawProvider.doRemove(Entity.Faultcurrent.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries were deleted"); + readOutput = dbProvider.readStatus().getData(); + assertEquals(0,readOutput.get(0).getFaults().getMajors().intValue()); + assertEquals(0,readOutput.get(0).getFaults().getMinors().intValue()); + assertEquals(0,readOutput.get(0).getFaults().getWarnings().intValue()); + assertEquals(0,readOutput.get(0).getFaults().getCriticals().intValue()); + } + + @Test + public void testMediatorServer() { + final String NAME = "ms1"; + final String URL = "http://11.23.45.55:4599"; + final String NAME2 = "ms1-nu"; + final String URL2 = "http://11.23.45.56:4599"; + + // ==CLEAR BEFORE TEST============================ + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.MediatorServer.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + trySleep(); + // ==CREATE============================ + System.out.println("try to create entry"); + CreateMediatorServerOutputBuilder createOutput = null; + CreateMediatorServerInput input = new CreateMediatorServerInputBuilder().setName(NAME).setUrl(URL).build(); + String dbId = null; + + try { + createOutput = dbProvider.createMediatorServer(input); + dbId = createOutput.getId(); + System.out.println(createOutput); + } catch (Exception e) { + fail("failed to create " + input.toString() + ":" + e.getMessage()); + } + assertNotNull(createOutput); + assertNotNull(dbId); + trySleep(); + // ==READ=========================== + System.out.println("try to read entry"); + ReadMediatorServerListInput readinput = new ReadMediatorServerListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + ReadMediatorServerListOutputBuilder readoutput = dbProvider.readMediatorServerList(readinput); + List<Data> data = readoutput.getData(); + assertNotNull(data); + assertEquals("no entry found", 1, data.size()); + assertEquals(NAME, data.get(0).getName()); + assertEquals(URL, data.get(0).getUrl()); + String dbId2 = data.get(0).getId(); + assertEquals(dbId, dbId2); + System.out.println(data); + // ==UPDATE============================ + System.out.println("try to update entry"); + UpdateMediatorServerInput updateInput = new UpdateMediatorServerInputBuilder().setId(dbId2).setName(NAME2) + .setUrl(URL2).build(); + UpdateMediatorServerOutputBuilder updateOutput = null; + try { + updateOutput = dbProvider.updateMediatorServer(updateInput); + System.out.println(updateOutput); + } catch (Exception e) { + fail("problem updating entry:" + e.getMessage()); + } + assertNotNull(updateOutput); + trySleep(); + // ==READ============================ + System.out.println("try to read entry"); + readinput = new ReadMediatorServerListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) + .setPagination(getPagination(20, 1)).build(); + readoutput = dbProvider.readMediatorServerList(readinput); + data = readoutput.getData(); + System.out.println(data); + assertNotNull("no update response", data); + assertEquals("update not verifiied", 1, data.size()); + assertEquals("update not verifiied", NAME2, data.get(0).getName()); + assertEquals("update not verifiied", URL2, data.get(0).getUrl()); + assertEquals("update not verifiied", dbId, data.get(0).getId()); + // ==DELETE============================ + System.out.println("try to delete entry"); + DeleteMediatorServerInput deleteInput = new DeleteMediatorServerInputBuilder().setId(dbId).build(); + try { + dbProvider.deleteMediatorServer(deleteInput); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + trySleep(); + // ==READ/VERIFY DELETE============================ + System.out.println("try to read entry"); + readinput = new ReadMediatorServerListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) + .setPagination(getPagination(20, 1)).build(); + readoutput = dbProvider.readMediatorServerList(readinput); + data = readoutput.getData(); + assertNotNull("delete not verifiied", data); + assertEquals("delete not verifiied", 0, data.size()); + } + + @Test + public void testNetworkElementConnectionCurrent() { + + System.out.println("networkElementConnection test start"); + + // ==CLEAR BEFORE TEST============================ + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.NetworkelementConnection.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + // ==CREATE============================ + System.out.println("try to create"); + final String name = "sim87"; + final String url = "10.5.10.1"; + final long port = 5959; + + CreateNetworkElementConnectionOutputBuilder create = null; + CreateNetworkElementConnectionInput input = new CreateNetworkElementConnectionInputBuilder().setNodeId(name) + .setIsRequired(true).setHost(url).setPort(port).build(); + String dbId = null; + + try { + create = dbProvider.createNetworkElementConnection(input); + dbId = create.getId(); + } catch (Exception e) { + fail("networkElementConnection create failed" + e.getMessage()); + } + + assertNotNull(dbId); + assertNotNull(create); + + // ==READ=========================== + + ReadNetworkElementConnectionListInput readInput = new ReadNetworkElementConnectionListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + + ReadNetworkElementConnectionListOutputBuilder readOperation = dbProvider + .readNetworkElementConnectionList(readInput); + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.network.element.connection.list.output.Data> data = readOperation + .getData(); + + assertNotNull(data); + assertEquals(dbId, data.get(0).getId()); + assertEquals(name, data.get(0).getNodeId()); + assertEquals(url, data.get(0).getHost()); + assertEquals(port, data.get(0).getPort().longValue()); + + // ==UPDATE============================ + System.out.println("Trying to update..."); + final String name2 = "sim88"; + final String url2 = "10.5.10.2"; + final long port2 = 5960; + + UpdateNetworkElementConnectionInput updateInput = new UpdateNetworkElementConnectionInputBuilder().setId(dbId).setHost(url2).setPort(port2).setIsRequired(false).build(); + UpdateNetworkElementConnectionOutputBuilder updateOutput = null; + try { + updateOutput = dbProvider.updateNetworkElementConnection(updateInput); + } catch (Exception e) { + fail("update failed: " + e.getMessage()); + } + + assertNotNull(updateOutput); + + // == Verify UPDATE============================ + System.out.println("Verfiying update..."); + + readOperation = dbProvider.readNetworkElementConnectionList(readInput); + data = readOperation.getData(); + + assertNotNull(data); + assertEquals(url2, data.get(0).getHost()); + assertEquals(port2, data.get(0).getPort().longValue()); + + // ==PARTIAL UPDATE============================ + System.out.println("Try partial update..."); + assertEquals(false, data.get(0).isIsRequired()); + updateInput = new UpdateNetworkElementConnectionInputBuilder().setId(dbId).setIsRequired(true).build(); + try { + updateOutput = dbProvider.updateNetworkElementConnection(updateInput); + } catch (Exception e) { + fail("update failed: " + e.getMessage()); + } + + assertNotNull(updateOutput); + + readOperation = dbProvider.readNetworkElementConnectionList(readInput); + data = readOperation.getData(); + + assertEquals(true, data.get(0).isIsRequired()); + assertEquals(url2, data.get(0).getHost()); + assertEquals(port2, data.get(0).getPort().longValue()); + + // ==DELETE============================ + System.out.println("Try delete..."); + + DeleteNetworkElementConnectionInput deleteInput = new DeleteNetworkElementConnectionInputBuilder().setId(dbId) + .build(); + try { + dbProvider.deleteNetworkElementConnection(deleteInput); + } catch (Exception e) { + fail("problem deleting "+e.getMessage()); + } + + readInput = new ReadNetworkElementConnectionListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + readOperation = dbProvider.readNetworkElementConnectionList(readInput); + data = readOperation.getData(); + assertEquals(0, data.size()); + + } + + @Test + public void testMaintenance() { + System.out.println("Starting Maintenance tests..."); + + // ==CLEAR BEFORE TEST============================ + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Maintenancemode.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + // ==CREATE============================ + + final String nodeId = "Lorem Ipsum"; + final boolean isActive = true; + + CreateMaintenanceOutputBuilder create = null; + CreateMaintenanceInput input = new CreateMaintenanceInputBuilder().setNodeId(nodeId).setActive(isActive) + .build(); + String dbId = null; + try { + create = dbProvider.createMaintenance(input); + dbId = create.getId(); + } catch (Exception e) { + fail("Failed to create:" + e.getMessage()); + } + + System.out.println(dbId); + assertNotNull(create); + assertNotNull(dbId); + + // ==READ=========================== + System.out.println("Try read..."); + + ReadMaintenanceListInput readinput = new ReadMaintenanceListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + ReadMaintenanceListOutputBuilder readResult = dbProvider.readMaintenanceList(readinput); + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.maintenance.list.output.Data> data = readResult + .getData(); + + assertNotEquals(0, data.size()); + assertNotNull(data); + assertEquals(nodeId, data.get(0).getNodeId()); + assertEquals(isActive, data.get(0).isActive()); + + // ==UPDATE============================ + + System.out.println("Trying to update..."); + final String nodeId2 = "Name2"; + final boolean isActive2 = false; + + UpdateMaintenanceInput updateInput = new UpdateMaintenanceInputBuilder().setId(dbId).setNodeId(nodeId2) + .setActive(isActive2).build(); + UpdateMaintenanceOutputBuilder updateResult = null; + try { + updateResult = dbProvider.updateMaintenance(updateInput); + } catch (Exception e) { + fail("maintenance update failed..." + e.getMessage()); + } + + assertNotNull(updateResult); + + // == VERIFY UPDATE============================ + System.out.println("Verfify update..."); + readResult = dbProvider.readMaintenanceList(readinput); + data = readResult.getData(); + + assertNotNull(data); + assertEquals(nodeId2, data.get(0).getNodeId()); + assertEquals(isActive2, data.get(0).isActive()); + + // ==DELETE================================ + System.out.println("Trying to delete..."); + + DeleteMaintenanceInput deleteInput = new DeleteMaintenanceInputBuilder().setId(dbId).build(); + try { + dbProvider.deleteMaintenance(deleteInput); + } catch (Exception e) { + fail("Maintenance entry couldn't be deleted" + e.getMessage()); + } + + readResult = dbProvider.readMaintenanceList(readinput); + data = readResult.getData(); + + assertEquals(0, data.size()); + } + + @Test + public void testFaultLog() { + + System.out.println("Starting fault log tests..."); + String dbId = clearAndCreatefaultEntity("1", Entity.Faultlog.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultlogInput", SeverityType.Critical); + + // ==READ=========================== + System.out.println("try to read entry"); + + ReadFaultlogListInput readinput = new ReadFaultlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + + ReadFaultlogListOutputBuilder readResult = null; + try { + readResult = dbProvider.readFaultLogList(readinput); + + } catch (Exception e) { + fail("Fault log not read: " + e.getMessage()); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.faultlog.list.output.Data> data = readResult + .getData(); + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("signalIsLost", data.get(0).getProblem()); + assertEquals("Critical", data.get(0).getSeverity().toString()); + assertEquals("s1", data.get(0).getNodeId()); + + //== UPDATE ================================ + System.out.println("try to update entry"); + + dbRawProvider.doUpdateOrCreate(Entity.Faultlog.getName(), "1", "{'problem': 'CableLOS', 'severity': 'Major', 'node-id': 'test4657-78'}"); + + System.out.println("try to search entry 1"); + readinput = new ReadFaultlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-id").setFiltervalue("test").build())) + .setPagination(getPagination(20, 1)).build(); + + //== VERIFY UPDATE ================================ + readResult = dbProvider.readFaultLogList(readinput); + data = readResult.getData(); + + + assertNotNull(data); + System.out.println(data); + assertEquals(0, data.size()); + + System.out.println("try to search entry 2"); + + readinput = new ReadFaultlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build())) + .setPagination(getPagination(20, 1)).build(); + + readResult = dbProvider.readFaultLogList(readinput); + data = readResult.getData(); + + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("CableLOS", data.get(0).getProblem()); + assertEquals("Major", data.get(0).getSeverity().toString()); + assertEquals("test4657-78", data.get(0).getNodeId()); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Faultlog.getName(), dbId); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + readResult = dbProvider.readFaultLogList(new ReadFaultlogListInputBuilder().setPagination(getPagination(20, 1)).build()); + data = readResult.getData(); + assertEquals(0, data.size()); + } + + @Test + public void testFaultCurrent() { + System.out.println("Starting faultCurrent test..."); + String dbId = null; + dbId = clearAndCreatefaultEntity("1", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.NonAlarmed); + assertEquals("1", dbId); + + // ==READ=========================== + System.out.println("Trying to read..."); + + + ReadFaultcurrentListInput readinput = new ReadFaultcurrentListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + + ReadFaultcurrentListOutputBuilder readResult = null; + try { + readResult = dbProvider.readFaultCurrentList(readinput); + + } catch (Exception e) { + fail("Fault log not read: " + e.getMessage()); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.faultcurrent.list.output.Data> data = readResult + .getData(); + + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("signalIsLost", data.get(0).getProblem()); + assertEquals("NonAlarmed", data.get(0).getSeverity().toString()); + assertEquals("s1", data.get(0).getNodeId()); + assertEquals(4340, data.get(0).getCounter().intValue()); + assertEquals(new DateAndTime("2019-10-28T11:55:58.3Z"), data.get(0).getTimestamp()); + assertEquals(4340, data.get(0).getCounter().intValue()); + assertEquals("LP-MWPS-RADIO", data.get(0).getObjectId()); + + + // ==UPDATE============================ + System.out.println("Trying to update..."); + + String json = "{\n" + + "\"timestamp\": \"2019-12-28T11:55:58.3Z\",\n" + + "\"node-id\": \"SDN-Controller-0\",\n" + + "\"counter\": 75,\n" + + "\"problem\": \"connectionLossNeOAM\",\n" + + "}"; + + String updatedDbId = dbRawProvider.doUpdateOrCreate(Entity.Faultcurrent.getName(), dbId, json); + assertEquals(dbId, updatedDbId); + + // ==READ============================ + + try { + readResult = dbProvider.readFaultCurrentList(readinput); + + } catch (Exception e) { + fail("Fault log not read: " + e.getMessage()); + } + + data = readResult.getData(); + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("connectionLossNeOAM", data.get(0).getProblem()); + assertEquals("SDN-Controller-0", data.get(0).getNodeId()); + assertEquals(75, data.get(0).getCounter().intValue()); + assertEquals("LP-MWPS-RADIO", data.get(0).getObjectId()); + + // ==DELETE============================ + try { + dbRawProvider.doRemove(Entity.Faultcurrent.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + // ==READ/VERIFY DELETE============================ + + try { + readResult = dbProvider.readFaultCurrentList(readinput); + + } catch (Exception e) { + fail("Fault log not read: " + e.getMessage()); + } + + data = readResult.getData(); + + assertNotNull(data); + assertEquals(0, data.size()); + } + + @Test + public void testConnectionLog() { + + // ==CLEAR================================ + System.out.println("Clear before test"); + try { + dbRawProvider.doRemove(Entity.Connectionlog.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + // ==CREATE================================ + + System.out.println("Try create entry"); + final String initialDbId = "1"; + String dbId = null; + String json ="{\n" + + "\"timestamp\": \"2019-11-01T11:28:34.7Z\",\n" + + "\"status\": \"Connecting\",\n" + + "\"node-id\": \"sim2230\",\n" + + "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateConnectionlogInput\"\n" + + "}"; + + dbId = dbRawProvider.doUpdateOrCreate(Entity.Connectionlog.getName(), initialDbId, json); + + assertEquals(initialDbId, dbId); + + // ==READ================================ + System.out.println("Try read entry"); + + ReadConnectionlogListInput readinput = new ReadConnectionlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + + ReadConnectionlogListOutputBuilder readResult = null; + try { + readResult = dbProvider.readConnectionlogList(readinput); + + } catch (Exception e) { + fail("Connection log not read: " + e.getMessage()); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.connectionlog.list.output.Data> data = readResult + .getData(); + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("Connecting", data.get(0).getStatus().toString()); + assertEquals("sim2230", data.get(0).getNodeId()); + + + // ==UPDATE================================ + System.out.println("Try update entry"); + + dbRawProvider.doUpdateOrCreate(Entity.Connectionlog.getName(), dbId, "{'status' : 'Connected'}"); + + // ==READ 2================================ + System.out.println("Try read updated entry"); + + readinput = new ReadConnectionlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("status").setFiltervalue("Connected").build())) + .setPagination(getPagination(20, 1)).build(); + + try { + readResult = dbProvider.readConnectionlogList(readinput); + + } catch (Exception e) { + fail("Connection log not read: " + e.getMessage()); + } + + data = readResult.getData(); + + assertNotNull(data); + assertEquals(1, data.size()); + assertEquals("Connected", data.get(0).getStatus().toString()); + assertEquals("sim2230", data.get(0).getNodeId()); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Connectionlog.getName(), dbId); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + readResult = dbProvider.readConnectionlogList(new ReadConnectionlogListInputBuilder().setPagination(getPagination(20, 1)).build()); + data = readResult.getData(); + assertEquals(0, data.size()); + + } + + @Test + public void testEventLog() { + System.out.println("Test event log starting..."); + + // ==CLEAR================================ + System.out.println("Clear before test"); + try { + dbRawProvider.doRemove(Entity.Eventlog.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + // ==CREATE============================ + + String dbId = null; + String json = " {\n" + + "\"timestamp\": \"2019-11-08T16:39:23.0Z\",\n" + + "\"new-value\": \"done\",\n" + + "\"object-id\": \"SDN-Controller-0\",\n" + + "\"attribute-name\": \"startup\",\n" + + "\"counter\": 0,\n" + + "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Eventlog\",\n" + + "\"node-id\": \"SDN-Controller-0\"\n" + + "}"; + + dbId = dbRawProvider.doUpdateOrCreate(Entity.Eventlog.getName(), "1", json); + assertNotNull(dbId); + + // ==READ=========================== + + ReadEventlogListInput readinput = new ReadEventlogListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + ReadEventlogListOutputBuilder readResult = null; + try { + readResult = dbProvider.readEventlogList(readinput); + + } catch (Exception e) { + fail("problem reading eventlog"); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.eventlog.list.output.Data> data = readResult.getData(); + assertEquals(1,data.size()); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Eventlog.getName(), dbId); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + try { + readResult = dbProvider.readEventlogList(new ReadEventlogListInputBuilder().setPagination(getPagination(20, 1)).build()); + } catch (IOException e) { + fail("problem reading eventlog"); + } + data = readResult.getData(); + assertEquals(0, data.size()); + + } + + @Test + public void testInventory() { + + System.out.println("Test inventory starting..."); + + // ==CLEAR================================ + System.out.println("Clear before test"); + try { + dbRawProvider.doRemove(Entity.Inventoryequipment.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + + // ==CREATE============================ + + String dbId = null; + String json = " {\"tree-level\": 1,\n" + + " \"parent-uuid\": \"SHELF-1.1.0.0\",\n" + + " \"node-id\": \"sim2\",\n" + + " \"uuid\": \"CARD-1.1.8.0\",\n" + + " \"contained-holder\": [ ],\n" + + " \"manufacturer-name\": \"Lorem Ipsum\",\n" + + " \"manufacturer-identifier\": \"ONF-Wireless-Transport\",\n" + + " \"serial\": \"sd-dsa-eqw\",\n" + + " \"date\": \"2008-10-21T00:00:00.0Z\",\n" + + "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory\",\n" + + " \"version\": \"unknown\",\n" + + " \"description\": \"WS/DS3\",\n" + + " \"part-type-id\": \"unknown\",\n" + + " \"model-identifier\": \"model-id-s3s\",\n" + + " \"type-name\": \"p4.module\"}"; + + dbId = dbRawProvider.doUpdateOrCreate(Entity.Inventoryequipment.getName(), "1 1", json); + assertNotNull(dbId); + + // ==READ=========================== + ReadInventoryListInput readinput = new ReadInventoryListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setPagination(getPagination(20, 1)).build(); + ReadInventoryListOutputBuilder readResult = null; + try { + readResult = dbProvider.readInventoryList(readinput); + + } catch (Exception e) { + fail("Problem reading inventory list"+e.getMessage()); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data> data = readResult.getData(); + assertEquals(1,data.size()); + assertEquals("Lorem Ipsum", data.get(0).getManufacturerName()); + assertEquals("ONF-Wireless-Transport", data.get(0).getManufacturerIdentifier()); + assertEquals("sim2", data.get(0).getNodeId()); + assertEquals("unknown", data.get(0).getVersion()); + assertEquals("WS/DS3", data.get(0).getDescription()); + assertEquals("2008-10-21T00:00:00.0Z", data.get(0).getDate()); + assertEquals("sd-dsa-eqw", data.get(0).getSerial()); + System.out.println(data.get(0).getDate()); + + // ==UPDATE============================ + String updatedDbId=null; + final String[] holderArray = {"Lorem Ipsum 1", "Lorem Ipsum 2", "Lorem Ipsum &%/$_2"}; + String updatejson = " {" + + " \"node-id\": \"sim5\",\n" + + " \"contained-holder\": [ \"Lorem Ipsum 1\", \"Lorem Ipsum 2\", \"Lorem Ipsum &%/$_2\" ],\n" + + " \"serial\": \"sd-dsa-eww\",\n" + + " \"date\": \"2008-11-21T00:00:00.0Z\",\n" + + " \"part-type-id\": \"not unknown\",\n" + + "}"; + + updatedDbId = dbRawProvider.doUpdateOrCreate(Entity.Inventoryequipment.getName(), dbId, updatejson); + assertEquals(dbId, updatedDbId); + + try { + readResult = dbProvider.readInventoryList(readinput); + + } catch (Exception e) { + fail("Problem reading inventory list"+e.getMessage()); + } + + data = readResult.getData(); + + assertEquals(1,data.size()); + assertEquals("Lorem Ipsum", data.get(0).getManufacturerName()); + assertEquals("ONF-Wireless-Transport", data.get(0).getManufacturerIdentifier()); + assertEquals("sim5", data.get(0).getNodeId()); + assertEquals("not unknown", data.get(0).getPartTypeId()); + assertEquals("WS/DS3", data.get(0).getDescription()); + assertEquals("2008-11-21T00:00:00.0Z", data.get(0).getDate()); + assertEquals("sd-dsa-eww", data.get(0).getSerial()); + assertEquals(holderArray.length,data.get(0).getContainedHolder().size()); + assertEquals(holderArray[0],data.get(0).getContainedHolder().get(0)); + assertEquals(holderArray[1],data.get(0).getContainedHolder().get(1)); + assertEquals(holderArray[2],data.get(0).getContainedHolder().get(2)); + + // ==DELETE============================ + + System.out.println("delete after test"); + try { + dbRawProvider.doRemove(Entity.Inventoryequipment.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + // ==VERIFY DELETE ============================ + + try { + readResult = dbProvider.readInventoryList(readinput); + + } catch (Exception e) { + fail("Problem reading inventory list"+e.getMessage()); + } + + data = readResult.getData(); + assertEquals(0,data.size()); + + } + + @Test + public void test15MinPerformanceReadLtpListWithoutNodeIdSetThrowsException() { + + System.out.println("Reading 15m ltp list without node id filter set throws an exception test start..."); + + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + System.out.println("create entries..."); + + createPerformanceData("1", GranularityPeriodType.Period15Min, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a2"); + createPerformanceData("2", GranularityPeriodType.Period15Min, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a2"); + + createPerformanceData("4", GranularityPeriodType.Period15Min, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a3"); + createPerformanceData("5", GranularityPeriodType.Period15Min, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a3"); + createPerformanceData("6", GranularityPeriodType.Period15Min, "PM_RADIO_15M_7", "LP-MWPS-TTP-03", "a3"); + createPerformanceData("3", GranularityPeriodType.Period15Min, "PM_RADIO_15M_7", "LP-MWPS-TTP-05", "a3"); + + System.out.println("trying to read, should throw exception..."); + + + ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder() + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata15mLtpListOutputBuilder readltpResult = null; + + try { + readltpResult = dbProvider.readPmdata15mLtpList(readLtp); + fail("No exception thrown!"); + } catch (Exception e) { + System.out.println(e); + assertTrue(e instanceof IllegalArgumentException); + assertEquals("no nodename in filter found ", e.getMessage()); + } + + assertNull(readltpResult); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> data = dbProvider.readPmdata15mList(new ReadPmdata15mListInputBuilder() + .setPagination(getPagination(20, 1)).build()).getData(); + + assertEquals(0, data.size()); + } + + @Test + public void test15MinPerformanceData() { + // == CLEAR BEFORE TESTS ============================ + System.out.println("Test 15 min performance..."); + + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + // == CREATE ============================ + + System.out.println("create entries..."); + + createPerformanceData("1", GranularityPeriodType.Period15Min, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a2"); + createPerformanceData("2", GranularityPeriodType.Period15Min, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a2"); + + createPerformanceData("4", GranularityPeriodType.Period15Min, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a3"); + createPerformanceData("5", GranularityPeriodType.Period15Min, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a3"); + createPerformanceData("6", GranularityPeriodType.Period15Min, "PM_RADIO_15M_7", "LP-MWPS-TTP-03", "a3"); + createPerformanceData("3", GranularityPeriodType.Period15Min, "PM_RADIO_15M_7", "LP-MWPS-TTP-05", "a3"); + + // == READ ============================ + System.out.println("read list entries..."); + + ReadPmdata15mListInput read = new ReadPmdata15mListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata15mListOutputBuilder readResult = null; + + try { + readResult = dbProvider.readPmdata15mList(read); + } catch (Exception e) { + fail("Problem reading 15m data"); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> data = readResult + .getData(); + + assertNotNull(data); + assertEquals(2, data.size()); + + System.out.println("read ltp entries with node name set..."); + + ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata15mLtpListOutputBuilder readltpResult = null; + + try { + readltpResult = dbProvider.readPmdata15mLtpList(readLtp); + } catch (Exception e) { + fail("Problem reading 15m ltp data"); + } + + List<String> dataLtp = readltpResult.getData(); + + assertNotNull(dataLtp); + assertEquals(2, dataLtp.size()); + assertTrue(dataLtp.contains("LP-MWPS-TTP-02")); + assertTrue(dataLtp.contains("LP-MWPS-TTP-01")); + + System.out.println("read device entries..."); + + ReadPmdata15mDeviceListInput readDevices = new ReadPmdata15mDeviceListInputBuilder() + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata15mDeviceListOutputBuilder readDeviceResult = null; + + try { + readDeviceResult = dbProvider.readPmdata15mDeviceList(readDevices); + } catch (Exception e) { + fail("Problem reading 15m device data"); + } + + List<String> dataDevice = readDeviceResult.getData(); + + assertNotNull(dataDevice); + assertEquals(2, dataDevice.size()); + assertTrue(dataDevice.contains("a2")); + assertTrue(dataDevice.contains("a3")); + + //== DELETE ================================ + + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + readResult = dbProvider.readPmdata15mList(new ReadPmdata15mListInputBuilder() + .setPagination(getPagination(20, 1)).build()); + data = readResult.getData(); + assertEquals(0, data.size()); + + } + + @Test + public void test24hPerformanceData() { + System.out.println("Test 24h performance..."); + + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + System.out.println("create entries..."); + GranularityPeriodType timeInterval = GranularityPeriodType.Period24Hours; + createPerformanceData("1", timeInterval, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a2"); + createPerformanceData("2", timeInterval, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a2"); + String aDbId = createPerformanceData("4", timeInterval, "PM_RADIO_15M_6", "LP-MWPS-TTP-06", "a2"); + + createPerformanceData("5", timeInterval, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a3"); + createPerformanceData("6", timeInterval, "PM_RADIO_15M_7", "LP-MWPS-TTP-03", "a3"); + createPerformanceData("3", timeInterval, "PM_RADIO_15M_7", "LP-MWPS-TTP-05", "a3"); + + System.out.println("read all list entries..."); + + ReadPmdata24hListInput read = new ReadPmdata24hListInputBuilder() + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata24hListOutputBuilder readResult = null; + + try { + readResult = dbProvider.readPmdata24hList(read); + } catch (Exception e) { + fail("Problem reading 24h data"); + } + + List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._24h.list.output.Data> data = readResult + .getData(); + + assertNotNull(data); + assertEquals(6, data.size()); + + + System.out.println("filter list entries..."); + + read = new ReadPmdata24hListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); + + readResult = null; + + try { + readResult = dbProvider.readPmdata24hList(read); + } catch (Exception e) { + fail("Problem reading 24h data"); + } + + data = readResult.getData(); + + assertNotNull(data); + assertEquals(3, data.size()); + + System.out.println("read ltp entries with node name set..."); + + ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata24hLtpListOutputBuilder readltpResult = null; + + try { + readltpResult = dbProvider.readPmdata24hLtpList(readLtp); + } catch (Exception e) { + fail("Problem reading 24h ltp data"); + } + + List<String> dataLtp = readltpResult.getData(); + + assertNotNull(dataLtp); + assertEquals(3, dataLtp.size()); + assertTrue(dataLtp.contains("LP-MWPS-TTP-02")); + assertTrue(dataLtp.contains("LP-MWPS-TTP-01")); + assertTrue(dataLtp.contains("LP-MWPS-TTP-06")); + + + System.out.println("read device entries..."); + + ReadPmdata24hDeviceListInput readDevices = new ReadPmdata24hDeviceListInputBuilder() + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata24hDeviceListOutputBuilder readDeviceResult = null; + + try { + readDeviceResult = dbProvider.readPmdata24hDeviceList(readDevices); + } catch (Exception e) { + fail("Problem reading 24h device data"); + } + + List<String> dataDevice = readDeviceResult.getData(); + + assertNotNull(dataDevice); + assertEquals(2, dataDevice.size()); + assertTrue(dataDevice.contains("a2")); + assertTrue(dataDevice.contains("a3")); + + // == UPDATE ============================== + + String shouldbeEmpty = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); + assertEquals("",shouldbeEmpty); + try { + readltpResult = dbProvider.readPmdata24hLtpList(readLtp); + } catch (Exception e) { + fail("Problem reading 24h ltp data"); + } + + // == VERIFY UPDATE ============================== + + dataLtp = readltpResult.getData(); + + assertNotNull(dataLtp); + assertEquals(3, dataLtp.size()); + assertTrue(dataLtp.contains("LP-MWPS-TTP-02")); + assertTrue(dataLtp.contains("LP-MWPS-TTP-01")); + assertTrue(dataLtp.contains("LTP-TEST-MWP-097")); + + + + //== DELETE =========================== + + System.out.println("try to clear entries"); + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting entry: " + e.getMessage()); + } + + //== VERIFY DELETE =========================== + System.out.println("verify entries deleted"); + readResult = dbProvider.readPmdata24hList(new ReadPmdata24hListInputBuilder() + .setPagination(getPagination(20, 1)).build()); + data = readResult.getData(); + assertEquals(0, data.size()); + } + + @Test + public void test24hPerformanceDataReadLtpListWithoutNodeIdSetThrowsException() { + System.out.println("Test 24 hour tp list without node id filter set throws an exception test start...\"..."); + + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + System.out.println("create entries..."); + + GranularityPeriodType timeInterval = GranularityPeriodType.Period24Hours; + createPerformanceData("1", timeInterval, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a2"); + createPerformanceData("2", timeInterval, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a2"); + + createPerformanceData("4", timeInterval, "PM_RADIO_15M_6", "LP-MWPS-TTP-02", "a3"); + createPerformanceData("5", timeInterval, "PM_RADIO_15M_4", "LP-MWPS-TTP-01", "a3"); + createPerformanceData("6", timeInterval, "PM_RADIO_15M_7", "LP-MWPS-TTP-03", "a3"); + createPerformanceData("3", timeInterval, "PM_RADIO_15M_7", "LP-MWPS-TTP-05", "a3"); + + System.out.println("trying to read, should throw exception..."); + + + ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder() + .setPagination(getPagination(20, 1)).build(); + + ReadPmdata24hLtpListOutputBuilder readltpResult = null; + + try { + readltpResult = dbProvider.readPmdata24hLtpList(readLtp); + fail("No exception thrown!"); + } catch (Exception e) { + System.out.println(e); + assertTrue(e instanceof IllegalArgumentException); + assertEquals("no nodename in filter found ", e.getMessage()); + } + + assertNull(readltpResult); + + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + } + + @Test + public void testUrlEncoding() { + System.out.println("Testing url encding"); + + final String test = "Lorem Ipsum"; + final String test1 = "Lorem/Ipsum"; + final String test2 = "Lorem_Ipsum"; + final String test3 = "Lorem%Ipsum"; + + assertEquals("Lorem%20Ipsum", BaseRequest.urlEncodeValue(test)); + assertEquals("Lorem%2FIpsum", BaseRequest.urlEncodeValue(test1)); + assertEquals("Lorem_Ipsum", BaseRequest.urlEncodeValue(test2)); + assertEquals("Lorem%25Ipsum", BaseRequest.urlEncodeValue(test3)); + } + + @Test + public void testDoUpdateOrCreateWithNullId() { + System.out.println("Test DoUpdateOrCreate doesn't create new database entry if null is passed"); + + String dbId = clearAndCreatefaultEntity(null, Entity.Faultlog.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultlogInput", SeverityType.Critical); + assertNull(dbId); + } + + @Test + public void readTestFaultCurrentViaRawDbProvider() { + System.out.println("Starting faultCurrent test..."); + String dbId = null; + dbId = clearAndCreatefaultEntity("1", Entity.Faultcurrent.getName(), "org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput", SeverityType.Critical); + assertEquals("1", dbId); + + // ==READ=========================== + System.out.println("Trying to read..."); + + String readResult = null; + try { + readResult = dbRawProvider.doReadJsonData(Entity.Faultcurrent.getName(), dbId); + + } catch (Exception e) { + fail("Fault log not read: " + e.getMessage()); + } + + + String expectedDbResult ="{\"severity\":\"Critical\",\"node-id\":\"s1\",\"problem\":\"signalIsLost\",\"counter\":4340,\"object-id\":\"LP-MWPS-RADIO\",\"implemented-interface\":\"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateFaultcurrentInput\",\"type\":\"ProblemNotificationXml\",\"timestamp\":\"2019-10-28T11:55:58.3Z\"}"; + + System.out.println(readResult); + assertNotNull(readResult); + assertEquals(expectedDbResult, readResult); + + SearchResult<SearchHit> searchResult = dbRawProvider.doReadAllJsonData(Entity.Faultcurrent.getName()); + assertNotNull(searchResult); + + List<SearchHit> hits = searchResult.getHits(); + + assertNotNull(hits); + assertEquals(1, searchResult.getTotal()); + assertEquals(expectedDbResult, hits.get(0).getSourceAsString()); + + //== DELETE ============================== + try { + dbRawProvider.doRemove(Entity.Faultcurrent.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + //== VERIFY DELETE ======================== + searchResult = dbRawProvider.doReadAllJsonData(Entity.Faultcurrent.getName()); + hits = searchResult.getHits(); + assertNotNull(hits); + assertEquals(0, searchResult.getTotal()); + + } + + + private Pagination getPagination(long pageSize, int page) { + return new PaginationBuilder().setPage(BigInteger.valueOf(page)).setSize(pageSize).build(); + } + + + private String clearAndCreatefaultEntity(String initialDbId, String entityType, String implementedInterface, SeverityType severity) { + // ==CLEAR BEFORE TEST============================ + System.out.println("try to clear entry"); + try { + dbRawProvider.doRemove(entityType, QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + + + return createFaultEntity(initialDbId, entityType, implementedInterface, severity); + } + + private String createFaultEntity(String initialDbId, String entityType, String implementedInterface, SeverityType severity) { + // ==CREATE============================ + System.out.println("try to create entry"); + String dbId = null; + + try { + + dbId = dbRawProvider.doUpdateOrCreate(entityType, initialDbId,"{\n" + + "\"timestamp\": \"2019-10-28T11:55:58.3Z\",\n" + + "\"object-id\": \"LP-MWPS-RADIO\",\n" + + "\"severity\": \""+severity.toString()+"\",\n" + + "\"node-id\": \"s1\",\n" + + "\"implemented-interface\": \""+implementedInterface+"\",\n" + + "\"counter\": 4340,\n" + + "\"problem\": \"signalIsLost\",\n" + + "\"type\": \"ProblemNotificationXml\"\n" + + "}"); + + + + } catch (Exception e) { + fail("Problem creating fault log entry" + e.getMessage()); + } + + return dbId; + } + + private String createPerformanceData(String initialDbId, GranularityPeriodType timeInterval, String scannerId, String uuidInterface, String nodename) { + + String json = "{\n" + + "\"node-name\": \""+nodename+"\",\n" + + "\"uuid-interface\": \""+uuidInterface+"\",\n" + + "\"layer-protocol-name\": \"MWPS\",\n" + + "\"radio-signal-id\": \"Test8\",\n" + + "\"time-stamp\": \"2017-03-01T06:15:00.0Z\",\n" + + "\"granularity-period\": \""+timeInterval.toString()+"\",\n" + + "\"scanner-id\": \""+scannerId+"\",\n" + + "\"performance-data\": {\n" + + "\"cses\": 0,\n" + + "\"ses\": 0,\n" + + "\"es\": 0,\n" + + "\"tx-level-max\": 3,\n" + + "\"tx-level-avg\": 3,\n" + + "\"rx-level-min\": -44,\n" + + "\"rx-level-max\": -45,\n" + + "\"rx-level-avg\": -44,\n" + + "\"time2-states\": 0,\n" + + "\"time4-states-s\": 0,\n" + + "\"time4-states\": 0,\n" + + "\"time8-states\": -1,\n" + + "\"time16-states-s\": -1,\n" + + "\"time16-states\": 0,\n" + + "\"time32-states\": -1,\n" + + "\"time64-states\": 900,\n" + + "\"time128-states\": -1,\n" + + "\"time256-states\": -1,\n" + + "\"time512-states\": -1,\n" + + "\"time512-states-l\": -1,\n" + + "\"unavailability\": 0,\n" + + "\"tx-level-min\": 3,\n" + + "\"time1024-states\": -1,\n" + + "\"time1024-states-l\": -1,\n" + + "\"time2048-states\": -1,\n" + + "\"time2048-states-l\": -1,\n" + + "\"time4096-states\": -1,\n" + + "\"time4096-states-l\": -1,\n" + + "\"time8192-states\": -1,\n" + + "\"time8192-states-l\": -1,\n" + + "\"snir-min\": -99,\n" + + "\"snir-max\": -99,\n" + + "\"snir-avg\": -99,\n" + + "\"xpd-min\": -99,\n" + + "\"xpd-max\": -99,\n" + + "\"xpd-avg\": -99,\n" + + "\"rf-temp-min\": -99,\n" + + "\"rf-temp-max\": -99,\n" + + "\"rf-temp-avg\": -99,\n" + + "\"defect-blocks-sum\": -1,\n" + + "\"time-period\": 900\n" + + "},\n" + + "\"suspect-interval-flag\": false\n" + + "}"; + + if(timeInterval.equals(GranularityPeriodType.Period15Min)) { + return dbRawProvider.doUpdateOrCreate(Entity.Historicalperformance15min.getName(), initialDbId, json); + }else { + return dbRawProvider.doUpdateOrCreate(Entity.Historicalperformance24h.getName(), initialDbId, json); + } + } + +} 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 new file mode 100644 index 000000000..7ff547fa5 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============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.File; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.EsConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestConfig { + + private static final Logger LOG = LoggerFactory.getLogger(TestConfig.class); + + private static final String TESTFILENAME = "testconfig.properties"; + + @After + @Before + public void afterAndBefore() { + File f=new File(TESTFILENAME); + if(f.exists()) { + LOG.info("Remove {}", f.getAbsolutePath()); + f.delete(); + } + } + @Test + public void test() { + ConfigurationFileRepresentation configuration=new ConfigurationFileRepresentation(TESTFILENAME); + + EsConfig esConfig = new EsConfig(configuration); + LOG.info("Defaultconfiguration: {}", esConfig.toString()); + assertEquals("http", esConfig.getHosts()[0].protocol.getValue()); + assertEquals(9200, esConfig.getHosts()[0].port); + assertEquals("sdnrdb", esConfig.getHosts()[0].hostname); + + } + +} 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 new file mode 100644 index 000000000..62d2bb597 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============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 java.io.File; + +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; + +public class TestConfiguration { + + private static final String CONFIGURATIONTESTFILE = "test.properties"; // for + + @Test + public void test1() throws ConfigurationException { + + System.out.println("Configuration file " + CONFIGURATIONTESTFILE); + + File testConfigurationFile = ResourceFileLoader.getFile(this, CONFIGURATIONTESTFILE); + System.out.println("Located at: "+testConfigurationFile.getAbsolutePath()); + + ConfigurationFileRepresentation configuration = new ConfigurationFileRepresentation(testConfigurationFile); + + System.out.println("Configuration: " + configuration.getSection(EsConfig.SECTION_MARKER_ES)); + EsConfig esConfig1 = new EsConfig(configuration); + + System.out.println("ES config getArchiveLifetimeSeconds: "+esConfig1.getArchiveLifetimeSeconds()); + + + // fail("Not yet implemented"); + } + + @Test + public void test2() { + + } + + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java new file mode 100644 index 000000000..5171aed6d --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * ============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 java.io.IOException; +import java.util.List; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; +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.config.HostInfo; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder; +import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +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.read.pmdata._15m.list.output.Data; +import org.opendaylight.yangtools.yang.binding.DataObject; + +public class TestDataMappings { + + private static final HostInfo[] HOSTINFOS = new HostInfo[] {HostInfo.getDefault()}; + //public static final String ESDATATYPENAME = "faultcurrent"; + + private static class HtDatabaseClientHelper extends HtDatabaseClient { + + private final String json; + + public HtDatabaseClientHelper(String jsonResponse, HostInfo[] hosts) { + super(hosts); + this.json = jsonResponse; + + } + + @Override + public SearchResult<SearchHit> doReadByQueryJsonData(String dataTypeName, QueryBuilder qb) { + return new SearchResult<>(new SearchResponse(this.json).getHits()); + } + } + + private static class MapResult<T extends DataObject> { + public final List<T> mappedData; + public MapResult(String dataType, Class<T> cls, String dbJson) throws ClassNotFoundException { + System.out.println(dbJson); + DatabaseClient db = new HtDatabaseClientHelper(dbJson,HOSTINFOS); + EsDataObjectReaderWriter<T> dbrw=new EsDataObjectReaderWriter<>(db,dataType,cls); + this.mappedData=dbrw.doReadAll().getHits(); + } + } + + private static final String SEARCHJSON_FORMAT = "{\n" + + "\"took\": 0,\n" + + "\"timed_out\": false,\n" + + "\"_shards\": {\n" + + "\"total\": 5,\n" + + "\"successful\": 5,\n" + + "\"skipped\": 0,\n" + + "\"failed\": 0\n" + + "},\n" + + "\"hits\": {\n" + + "\"total\": 1,\n" + + "\"max_score\": 1,\n" + + "\"hits\": [\n" + + "{\n" + + "\"_index\": \"%s\",\n" + + "\"_type\": \"%s\",\n" + + "\"_id\": \"%s\",\n" + + "\"_score\": 1,\n" + + "\"_source\": %s}\n" + + "]\n" + + "}\n" + + "}"; + + private static final String MEDIATORSERVER_DB_ID="LumwSG0BFvcE3yf8MBM5"; + private static final String MEDIATOR_SERVERDB_JSON = "{\"url\":\"https://10.45.44.223:7590\",\"name\":\"test mediator server\"}"; + + private static final String FAULTCURRENT_DB_ID="LumwSG0BFvcE3yf8MBM5"; + private static final String FAULTCURRENT_DB_NODEID = "sim1"; + private static final int FAULTCURRENT_DB_COUNTER = 3; + private static final String FAULTCURRENT_DB_OBJECTID = "LPS-MWT-01"; + private static final String FAULTCURRENT_DB_PROBLEM = "rlsExceeded"; + private static final String FAULTCURRENT_DB_SEVERITY = "critical"; + private static final DateAndTime FAULTCURRENT_DB_TIMESTAMP = DateAndTime.getDefaultInstance("2019-09-18T13:07:05.8Z"); + + private static final String FAULTCURRENT_SERVERDB_JSON = "{\"node-id\":\""+FAULTCURRENT_DB_NODEID+"\","+ + "\"counter\":"+FAULTCURRENT_DB_COUNTER+","+ + "\"object-id\":\""+FAULTCURRENT_DB_OBJECTID+"\","+ + "\"problem\":\""+FAULTCURRENT_DB_PROBLEM+"\","+ + "\"timestamp\":\""+FAULTCURRENT_DB_TIMESTAMP.getValue()+"\","+ + "\"severity\":\""+FAULTCURRENT_DB_SEVERITY+"\""+ + "}"; + + + private static final String PMDATA15M_SERVERDB_JSON="{\n" + + "\"node-name\": \"sim2\",\n" + + "\"uuid-interface\": \"LP-MWPS-TTP-01\",\n" + + "\"layer-protocol-name\": \"MWPS\",\n" + + "\"radio-signal-id\": \"Test11\",\n" + + "\"time-stamp\": \"2017-07-04T14:00:00.0Z\",\n" + + "\"granularity-period\": \"PERIOD_15MIN\",\n" + + "\"scanner-id\": \"PM_RADIO_15M_9\",\n" + + "\"performance-data\": {\n" + + "\"es\": 0,\n" + + "\"rx-level-avg\": -41,\n" + + "\"time2-states\": -1,\n" + + "\"time4-states-s\": 0,\n" + + "\"time4-states\": 0,\n" + + "\"time8-states\": 0,\n" + + "\"time16-states-s\": -1,\n" + + "\"time16-states\": 0,\n" + + "\"time32-states\": 0,\n" + + "\"time64-states\": 0,\n" + + "\"time128-states\": 0,\n" + + "\"time256-states\": 900,\n" + + "\"time512-states\": -1,\n" + + "\"time512-states-l\": -1,\n" + + "\"time1024-states\": -1,\n" + + "\"time1024-states-l\": -1,\n" + + "\"time2048-states\": -1,\n" + + "\"time2048-states-l\": -1,\n" + + "\"time4096-states\": -1,\n" + + "\"time4096-states-l\": -1,\n" + + "\"time8192-states\": -1,\n" + + "\"time8192-states-l\": -1,\n" + + "\"snir-min\": -99,\n" + + "\"snir-max\": -99,\n" + + "\"snir-avg\": -99,\n" + + "\"xpd-min\": -99,\n" + + "\"xpd-max\": -99,\n" + + "\"xpd-avg\": -99,\n" + + "\"rf-temp-min\": -99,\n" + + "\"rf-temp-max\": -99,\n" + + "\"rf-temp-avg\": -99,\n" + + "\"defect-blocks-sum\": -1,\n" + + "\"time-period\": 900,\n" + + "\"tx-level-min\": 25,\n" + + "\"tx-level-max\": 25,\n" + + "\"tx-level-avg\": 25,\n" + + "\"rx-level-min\": -41,\n" + + "\"rx-level-max\": -41,\n" + + "\"unavailability\": 0,\n" + + "\"ses\": 0,\n" + + "\"cses\": 0\n" + + "},\n" + + "\"suspect-interval-flag\": false\n" + + "}"; + + //@Test +// public void testMediatorServer() throws ClassNotFoundException { +// +// MapResult<EsMediatorServer> result = new MapResult<EsMediatorServer>(EsMediatorServer.ESDATATYPENAME, +// EsMediatorServer.class, +// getSearchJson(EsMediatorServer.ESDATATYPENAME,MEDIATORSERVER_DB_ID,MEDIATOR_SERVERDB_JSON)); +// assertEquals("test mediator server", result.mappedData.get(0).getName()); +// assertEquals("https://10.45.44.223:7590", result.mappedData.get(0).getUrl()); +// assertEquals(MEDIATORSERVER_DB_ID, result.mappedData.get(0).getId()); +// +// } + //@Test +// public void testFaultCurrent() { +// +// MapResult<FaultcurrentEntity> result = new MapResult<FaultcurrentEntity>(ESDATATYPENAME, EsFaultCurrent.class, +// getSearchJson(ESDATATYPENAME, FAULTCURRENT_DB_ID, FAULTCURRENT_SERVERDB_JSON)); +// assertEquals(FAULTCURRENT_DB_ID, result.mappedData.get(0).getId()); +// assertEquals(FAULTCURRENT_DB_NODEID, result.mappedData.get(0).getNodeId()); +// assertEquals(FAULTCURRENT_DB_COUNTER, result.mappedData.get(0).getCounter().intValue()); +// assertEquals(FAULTCURRENT_DB_OBJECTID, result.mappedData.get(0).getObjectId()); +// assertEquals(FAULTCURRENT_DB_PROBLEM, result.mappedData.get(0).getProblem()); +// assertEquals(FAULTCURRENT_DB_SEVERITY, result.mappedData.get(0).getSeverity()); +// assertEquals(FAULTCURRENT_DB_TIMESTAMP, result.mappedData.get(0).getTimestamp()); +// } +// + @Test + public void testPmData15m() { + + YangToolsMapper mapper = new YangToolsMapper(); + try { + Data data =mapper.readValue(PMDATA15M_SERVERDB_JSON.getBytes(), Data.class); + System.out.println(data); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + private String getSearchJson(String dataType,String dbId, String source) { + return String.format(SEARCHJSON_FORMAT,dataType,dataType, dbId,source); + } + +} 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 new file mode 100644 index 000000000..94381b6a3 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============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 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.entity.input.Filter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder; + +public class TestFilterConversion { + + private static final String PROPERTY = "node-id"; + + @Test + public void testQuestionMark() { + List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); + QueryBuilder query = QueryByFilter.fromFilter(filters ); + System.out.println(query.toJSON()); + } +} 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 new file mode 100644 index 000000000..633912579 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestInitalMaintenanceObjectInDatabase.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============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/TestNetconfNodeBuilder.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java new file mode 100644 index 000000000..0f502f83a --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfNodeBuilder.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============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 org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPassword; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; + +public class TestNetconfNodeBuilder { + + @SuppressWarnings("deprecation") + //@Test + public void test() { + + NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder(); + + LoginPasswordBuilder loginPasswordBuilder = new LoginPasswordBuilder(); + loginPasswordBuilder.setUsername("myTestUsername"); + loginPasswordBuilder.setPassword("myTestPassword"); + netconfNodeBuilder.setCredentials(loginPasswordBuilder.build()); + + NetconfNode netconfNode = netconfNodeBuilder.build(); + System.out.println(netconfNode); + + Credentials credentials = netconfNode.getCredentials(); + System.out.println("Class: "+credentials.getClass()+"\nContent: "+credentials); + + if (credentials instanceof LoginPassword) { + LoginPassword loginPassword = (LoginPassword)credentials; + System.out.println("User: "+loginPassword.getUsername()+" Password"+loginPassword.getPassword()); + } else { + System.out.println("Not expected class"); + } + } + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java new file mode 100644 index 000000000..d125af134 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNetconfTimestamp.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * ============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.util.Calendar; +import java.util.Date; +import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; + +public class TestNetconfTimestamp { + + + private static final String regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.?[0-9]?Z"; + private static final String NETCONF_DEF_MILLIS_STRING = "2020-01-09T05:40:41.1Z"; + private static final String NETCONF_DEF_MILLIS_STRING_MALFORMAED = "2020-01-09T05:40:41:0Z"; + private static final String NETCONF_DEF2_MILLIS_STRING = "2020-01-09T05:40:41.111Z"; + private static final String NETCONF_DEF3_MILLIS_STRING = "2020-01-09T05:40:41Z"; + private static final String NETCONF_DEF3_MILLIS_STRING_CORRECTED = "2020-01-09T05:40:41.0Z"; + private static final String NETCONF_DEF4_MILLIS_STRING_MALFORMAED = "2020-01-09T05:40:41.0000Z"; + private static final long NETCONF_DEF_MILLIS_LONG = 1578548441100L; + + private static NetconfTimeStamp converter =NetconfTimeStampImpl.getConverter(); + + @Test + public void test() { + String ts = converter.getTimeStampAsNetconfString(); + final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); + final Matcher matcher = pattern.matcher(ts); + assertTrue(matcher.find()); + } + @Test + public void testMillis() { + long millis=converter.getTimeStampFromNetconfAsMilliseconds(NETCONF_DEF_MILLIS_STRING); + assertEquals(NETCONF_DEF_MILLIS_LONG,millis); + + } + @Test(expected = IllegalArgumentException.class) + public void testMillisMalformed() { + long millis=converter.getTimeStampFromNetconfAsMilliseconds(NETCONF_DEF_MILLIS_STRING_MALFORMAED); + + } + + @Test + public void test2() { + assertEquals(NETCONF_DEF_MILLIS_STRING,converter.getTimeStampFromNetconf(NETCONF_DEF2_MILLIS_STRING)); + assertEquals(NETCONF_DEF3_MILLIS_STRING_CORRECTED,converter.getTimeStampFromNetconf(NETCONF_DEF3_MILLIS_STRING)); + assertTrue(converter.getTimeStampFromNetconf(NETCONF_DEF4_MILLIS_STRING_MALFORMAED).startsWith("Malformed")); + } + + @Test + public void test3() { + Date dt = converter.getDateFromNetconf(NETCONF_DEF_MILLIS_STRING); + final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c.setTime(dt); + assertEquals(2020,c.get(Calendar.YEAR)); + assertEquals(0,c.get(Calendar.MONTH)); + assertEquals(9,c.get(Calendar.DAY_OF_MONTH)); + assertEquals(5,c.get(Calendar.HOUR_OF_DAY)); + assertEquals(40,c.get(Calendar.MINUTE)); + assertEquals(41,c.get(Calendar.SECOND)); + assertEquals(100,c.get(Calendar.MILLISECOND)); + + + assertEquals(NETCONF_DEF_MILLIS_STRING,converter.getTimeStampAsNetconfString(dt)); + } +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java new file mode 100644 index 000000000..7f7c971ef --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * ============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 com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import java.io.IOException; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultcurrent; +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.SeverityType; + +public class TestNuMappings { + + @Test + public void test33() { + Faultcurrent c = new FaultcurrentBuilder().setSeverity(SeverityType.Critical).build(); + YangToolsMapper mapper = new YangToolsMapper(); + try { + System.out.println(mapper.writeValueAsString(c)+"<=>"+SeverityType.Critical.getName()); + } catch (JsonProcessingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + Faultcurrent f=mapper.readValue( "{\"severity\":\"Critical\"}", Faultcurrent.class); + System.out.println(f); + System.out.println(mapper.writeValueAsString(f)); + } catch (JsonParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JsonMappingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} 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 new file mode 100644 index 000000000..c32149ba5 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * ============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.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.json.JSONObject; +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.entity.input.Filter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.entity.input.FilterBuilder; + +public class TestTimestampFilter { + + + + @Test + public void testTimestampRange() { + final String PROPERTY_TIMESTAMP = "timestamp"; + List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2017*").build()); + QueryBuilder query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2017-01-01T00:00:00.0Z", "2018-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2000-01-01T00:00:00.0Z", "3000-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("20*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2000-01-01T00:00:00.0Z", "2100-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("205*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2060-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-01-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-1*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2051-01-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-11-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-11-01T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-0*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-01T00:00:00.0Z", "2050-10-10T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-02*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-02T00:00:00.0Z", "2050-10-03T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T00:00:00.0Z", "2050-10-15T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T00:00:00.0Z", "2050-10-15T00:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T1*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T10:00:00.0Z", "2050-10-14T20:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:00:00.0Z", "2050-10-14T13:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:00:00.0Z", "2050-10-14T13:00:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:4*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:40:00.0Z", "2050-10-14T12:50:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:00.0Z", "2050-10-14T12:43:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:00.0Z", "2050-10-14T12:43:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:5*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:50.0Z", "2050-10-14T12:43:00.0Z"); + + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2050-10-14T12:42:56*").build()); + query= QueryByFilter.fromFilter(filters ); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2050-10-14T12:42:56.0Z", "2050-10-14T12:42:57.0Z"); + } + private void assertRange(JSONObject rangeQuery,String property,String lower,String upper) { + System.out.println("==test for "+rangeQuery.toString()); + assertTrue(rangeQuery.has("range")); + assertTrue(rangeQuery.getJSONObject("range").has(property)); + JSONObject o=rangeQuery.getJSONObject("range").getJSONObject(property); + assertNotNull(o); + assertTrue(o.has("lt")); + assertEquals(upper, o.getString("lt")); + assertTrue(o.has("gte")); + assertEquals(lower, o.getString("gte")); + System.out.println("succeeded"); + } +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangCloning.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangCloning.java new file mode 100644 index 000000000..95e9c0b7a --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangCloning.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * ============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 java.util.Arrays; + +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultcurrent; +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.InventoryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.InventoryEntity; + +public class TestYangCloning { +/* + @Test + public void testEquipment() { + EquipmentBuilder equipmentBuilder = new EquipmentBuilder(); + equipmentBuilder.setUuid( new UniversalId("EquipmentId")); + equipmentBuilder.setContainedHolder(Arrays.asList(new ContainedHolderBuilder() + .setUuid(new UniversalId("HolderId")) + .setAdministrativeState(AdministrativeState.Locked) + .setSupportedEquipment(Arrays.asList("eq1")) + .build())); + Equipment equipment = equipmentBuilder.build(); + InventoryEntity output = YangToolsCloner.instance().cloneToBuilder(equipment, new InventoryBuilder()) + .setNodeId("node1").setUuid("a.a.a").setId("node1"+"/"+"a.a.a").build(); + + + System.out.println("source:"); + System.out.println(equipment); + System.out.println("result:"); + System.out.println(output); + + + } + @Test + public void testFaultCurrent() { + ProblemNotificationXml source = new ProblemNotificationXml("node", "uuid", "problem", InternalSeverity.Critical,54,InternalDateAndTime.getTestpattern()); + FaultcurrentEntity output = YangToolsCloner.instance().clone(source,Faultcurrent.class); + + System.out.println("source:"); + System.out.println(source); + System.out.println("result:"); + System.out.println(output); + } + */ +} 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 new file mode 100644 index 000000000..271b268ce --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java @@ -0,0 +1,406 @@ +/******************************************************************************* + * ============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 java.io.IOException; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.json.JSONObject; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +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.config.HostInfo.Protocol; +import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder; +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.dataprovider.database.EsDataObjectReaderWriter; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +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.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.OdlHelloMessageCapabilitiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; +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.Entity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EntityInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ReadPmdata15mListOutputBuilder; +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.PaginationBuilder; +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.pmdata15m.entity.PerformanceDataBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.DataBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.opendaylight.yangtools.yang.binding.DataObject; + +public class TestYangGenSalMapping { + + // Create mapper for serialization and deserialization + YangToolsMapper mapper = new YangToolsMapper(); + + @Test + public void test1() throws IOException { + + // Create test object + NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder(); + netconfNodeBuilder.setConnectedMessage("ConnMessage"); + + LoginPasswordBuilder loginPasswordBuilder = new LoginPasswordBuilder(); + loginPasswordBuilder.setUsername("myTestUsername"); + loginPasswordBuilder.setPassword("myTestPassword"); + netconfNodeBuilder.setCredentials(loginPasswordBuilder.build()); + + OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = new OdlHelloMessageCapabilitiesBuilder(); + List<Uri> uriList = new ArrayList<>(); + uriList.add( new Uri("test.uri") ); + odlHelloMessageCapabilitiesBuilder.setCapability(uriList); + netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build()); + + NetconfNode netconfNode = netconfNodeBuilder.build(); + out(netconfNode.toString()); + + // Map Object to JSON String + String res = mapper.writeValueAsString(netconfNode); + JSONObject json = new JSONObject(res); // Convert text to object + out(json.toString(4)); // Print it with specified indentation + + // Map to JSON String to Object + NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class); + out(generatedNode.toString()); // Print it with specified indentation + // Compare result + out("Equal? "+netconfNode.equals(generatedNode)); + } + + static class TestDataObjectBuilder implements Builder<TestDataObject> { + @Override + public @NonNull TestDataObject build() throws IllegalArgumentException { + return new TestDataObject(); + } + } + + static class TestDataObject implements DataObject { + String test; + + @Override + public Class<? extends DataContainer> getImplementedInterface() { + return null; + } + } + + @Test + public void test2() throws ClassNotFoundException { + + int databasePort = Integer.valueOf(System.getProperty("databaseport")!=null?System.getProperty("databaseport"):"49200"); + System.out.println("DB Port: "+databasePort); + + HostInfo[] HOSTINFOS = new HostInfo[] { new HostInfo("localhost", databasePort ,Protocol.HTTP)}; + DatabaseClient db = new HtDatabaseClient(HOSTINFOS); + + EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data> dataRW = + new EsDataObjectReaderWriter<>(db, "inventorytest", org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data.class); + + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d1; + d1 = getInventoryDataBuilder("MyDescription", 23L).build(); + String id = dataRW.write(d1,null); + + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.Data d2; + d2 = dataRW.read(id); + + out(d2.toString()); + + } + + @Test + public void test3() throws IOException { + + PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder(); + performanceBuilder.setEs(99); + DataBuilder pmData15MinutesBuilder = new DataBuilder(); + pmData15MinutesBuilder.setLayerProtocolName("fdsaf"); + pmData15MinutesBuilder.setTimeStamp(new DateAndTime("2017-03-01T09:15:00.0Z")); + pmData15MinutesBuilder.setPerformanceData(performanceBuilder.build()); + + // Map Object to JSON String + String res = mapper.writeValueAsString(pmData15MinutesBuilder.build()); + JSONObject json = new JSONObject(res); // Convert text to object + out(json.toString(4)); // Print it with specified indentation + + // Map to JSON String to Object + Data generatedNode = mapper.readValue(res.getBytes(), Data.class); + out(generatedNode.toString()); // Print it with specified indentation + } + + @Test + public void test4() throws IOException { + + String jsonString = "{\n" + "\"node-name\": \"Sim2230\",\n" + "\"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" + + "\"layer-protocol-name\": \"MWPS\",\n" + "\"radio-signal-id\": \"Test8\",\n" + + "\"time-stamp\": \"2017-03-01T09:15:00.0Z\",\n" + "\"granularity-period\": \"Period15Min\",\n" + + "\"scanner-id\": \"PM_RADIO_15M_4\",\n" + "\"performance-data\": {\n" + "\"unavailability\": 0,\n" + + "\"tx-level-max\": 3,\n" + "\"tx-level-avg\": 3,\n" + "\"rx-level-min\": -44,\n" + + "\"rx-level-max\": -45,\n" + "\"rx-level-avg\": -44,\n" + "\"time2-states\": 0,\n" + + "\"time4-states-s\": 0,\n" + "\"time4-states\": 0,\n" + "\"time8-states\": -1,\n" + + "\"time16-states-s\": -1,\n" + "\"time16-states\": 0,\n" + "\"time32-states\": -1,\n" + + "\"time64-states\": 900,\n" + "\"time128-states\": -1,\n" + "\"time256-states\": -1,\n" + + "\"time512-states\": -1,\n" + "\"time512-states-l\": -1,\n" + "\"time1024-states\": -1,\n" + + "\"time1024-states-l\": -1,\n" + "\"time8192-states-l\": -1,\n" + "\"time8192-states\": -1,\n" + + "\"time2048-states\": -1,\n" + "\"snir-min\": -99,\n" + "\"snir-max\": -99,\n" + + "\"snir-avg\": -99,\n" + "\"xpd-min\": -99,\n" + "\"xpd-max\": -99,\n" + "\"xpd-avg\": -99,\n" + + "\"rf-temp-min\": -99,\n" + "\"rf-temp-max\": -99,\n" + "\"rf-temp-avg\": -99,\n" + + "\"defect-blocks-sum\": -1,\n" + "\"time-period\": 900,\n" + "\"cses\": 0,\n" + + "\"time4096-states-l\": -1,\n" + "\"tx-level-min\": 3,\n" + "\"es\": 0,\n" + + "\"time2048-states-l\": -1,\n" + "\"time4096-states\": -1,\n" + "\"ses\": 0\n" + "},\n" + + "\"suspect-interval-flag\": false\n" + "}\n" + "}"; + // Map to JSON String to Object + Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class); + out(generatedNode.toString()); // Print it with specified indentation + + } + + + @Test + public void test5() throws IOException { + String jsonString = "{\n" + + " \"time-stamp\": \"2017-03-01T06:45:00.0Z\",\n" + + " \"node-name\": \"Sim2230\",\n" + + " \"uuid-interface\": \"LP-MWPS-TTP-RADIO\",\n" + + " \"scanner-id\": \"PM_RADIO_15M_14\",\n" + + " \"layer-protocol-name\": \"MWPS\",\n" + + " \"granularity-period\": \"Period15Min\",\n" + + " \"radio-signal-id\": \"Test8\",\n" + + " \"suspect-interval-flag\": false,\n" + + " \"performance-data\": {\n" + + " \"time4096-states-l\": -1,\n" + + " \"time16-states-s\": -1,\n" + + " \"tx-level-max\": 3,\n" + + " \"snir-max\": -99,\n" + + " \"time16-states\": 0,\n" + + " \"time64-states\": 900,\n" + + " \"unavailability\": 0,\n" + + " \"time8192-states-l\": -1,\n" + + " \"time512-states\": -1,\n" + + " \"xpd-min\": -99,\n" + + " \"xpd-avg\": -99,\n" + + " \"tx-level-avg\": 3,\n" + + " \"tx-level-min\": 3,\n" + + " \"rf-temp-min\": -99,\n" + + " \"rf-temp-avg\": -99,\n" + + " \"snir-avg\": -99,\n" + + " \"snir-min\": -99,\n" + + " \"time-period\": 900,\n" + + " \"time2-states\": 0,\n" + + " \"time4-states\": 0,\n" + + " \"time8-states\": -1,\n" + + " \"ses\": 0,\n" + + " \"time2048-states-l\": -1,\n" + + " \"time2048-states\": -1,\n" + + " \"xpd-max\": -99,\n" + + " \"rf-temp-max\": -99,\n" + + " \"time8192-states\": -1,\n" + + " \"time128-states\": -1,\n" + + " \"time256-states\": -1,\n" + + " \"rx-level-min\": -44,\n" + + " \"rx-level-avg\": -44,\n" + + " \"time1024-states-l\": -1,\n" + + " \"es\": 0,\n" + + " \"cses\": 0,\n" + + " \"time4-states-s\": 0,\n" + + " \"time1024-states\": -1,\n" + + " \"time512-states-l\": -1,\n" + + " \"time4096-states\": -1,\n" + + " \"rx-level-max\": -45,\n" + + " \"defect-blocks-sum\": -1,\n" + + " \"time32-states\": -1\n" + + " }\n" + + "}"; + + // Map to JSON String to Object + Data generatedNode = mapper.readValue(jsonString.getBytes(), Data.class); + out(generatedNode.toString()); // Print it with specified indentation + + } + + + @Test + public void test6() throws IOException, ClassNotFoundException { + out(method()); + HtDatabaseClient dbClient = new HtDatabaseClient(new HostInfo[] { new HostInfo("sdnrdb", 9200, Protocol.HTTP) }); + String PMDATA15M_TYPE = "historicalperformance15min"; + + EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> pm15mRW = + new EsDataObjectReaderWriter<>(dbClient, PMDATA15M_TYPE, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data.class); + pm15mRW.setEsIdAttributeName("_nodeName"); + + ReadPmdata15mListInputBuilder inputBuilder = new ReadPmdata15mListInputBuilder(); + PaginationBuilder paginationBuilder = new PaginationBuilder(); + paginationBuilder.setPage(new BigInteger("1")); + paginationBuilder.setSize(20L); + inputBuilder.setPagination(paginationBuilder.build()); + + ReadPmdata15mListInput input = inputBuilder.build(); + + + ReadPmdata15mListOutputBuilder outputBuilder = new ReadPmdata15mListOutputBuilder(); + long page = getPage(input); + long pageSize = getPageSize(input); + + QueryBuilder query = fromFilter(input.getFilter()).from((page - 1) * pageSize).size(pageSize); + setSortOrder(query, input.getSortorder()); + + SearchResult<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Data> result=pm15mRW.doReadAll(query); + + out("Found: "+result.getHits().size()); + int t=0; + for (Data hit : result.getHits()) { + out("Hit "+t+++":"+hit); + } + setPagination(outputBuilder, page, pageSize, result.getTotal()); + outputBuilder.setData(result.getHits()); + } + + @Test + public void test7() throws IOException, ClassNotFoundException { + out(method()); + String ESDATATYPE_MEDIATORSERVER = Entity.MediatorServer.getName(); + HtDatabaseClient dbClient = new HtDatabaseClient(new HostInfo[] { new HostInfo("sdnrdb", 9200, Protocol.HTTP) }); + EsDataObjectReaderWriter<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data> mediatorserverRW; + + mediatorserverRW = new EsDataObjectReaderWriter<>(dbClient, ESDATATYPE_MEDIATORSERVER, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.mediator.server.list.output.Data.class) + .setWriteInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MediatorServerEntity.class) + .setEsIdAttributeName("_id"); + + CreateMediatorServerInputBuilder inputBuilder = new CreateMediatorServerInputBuilder(); + inputBuilder.setName("Hans"); + inputBuilder.setUrl("MyGreatUrl"); + + String id = mediatorserverRW.write(inputBuilder.build(),"testid"); + System.out.println(id); + + } + + @Test + public void test8() throws IOException { + out(method()); + String input; + input = "id-dd-dd"; + System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + input = "idDdGg"; + System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + input = "_idDdGg"; + System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + input = "--ff--gfg"; + System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + input = ""; + System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + } + + /* --------------------------------- + * Private + */ + private static String method() { + String nameofCurrMethod = new Throwable().getStackTrace()[1].getMethodName(); + return nameofCurrMethod; + } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder getInventoryDataBuilder(String description, long treeLevel) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder dataBuilder = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.inventory.list.output.DataBuilder(); + dataBuilder.setDescription(description); + dataBuilder.setTreeLevel(treeLevel); + return dataBuilder; + } + + + private static void out(String text) { + System.out.println("----------------------"); + System.out.println(text); + } + + private static long getPage(EntityInput input) { + return getPage(input, 1); + } + + private static long getPage(EntityInput input, long defaultValue) { + return input.getPagination() != null ? input.getPagination().getPage().longValue() : defaultValue; + } + + private static long getPageSize(EntityInput input) { + return getPageSize(input, 1); + } + + private static long getPageSize(EntityInput input, long defaultValue) { + return input.getPagination() != null ? input.getPagination().getSize().longValue() : defaultValue; + } + + private static QueryBuilder fromFilter(@Nullable List<Filter> filters) { + return fromFilter(filters, ""); + } + + private static QueryBuilder fromFilter(@Nullable List<Filter> filters, String prefix) { + if (filters == null || filters.size() == 0) { + return QueryBuilders.matchAllQuery(); + + } else if(filters.size()==1){ + return QueryBuilders.matchQuery(filters.get(0).getProperty(), filters.get(0).getFiltervalue()); + } + else { + BoolQueryBuilder query = new BoolQueryBuilder(); + for (Filter fi : filters) { + query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + fi.getProperty(), + fi.getFiltervalue())); + } + return query; + } + + } + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder) { + return setSortOrder(query, sortorder, ""); + } + + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder, String prefix) { + if (sortorder != null && sortorder.size() > 0) { + for (Sortorder so : sortorder) { + query.sort((prefix != null ? prefix : "") + so.getProperty(), + so.getSortorder() == SortOrder.Ascending + ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING + : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING); + } + } + return query; + + } + + private static void setPagination(ReadPmdata15mListOutputBuilder outputBuilder, long page, long pageSize, long totalSize) { + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.Pagination value = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.read.pmdata._15m.list.output.PaginationBuilder() + .setPage(BigInteger.valueOf(page)).setSize(pageSize).setTotal(BigInteger.valueOf(totalSize)).build(); + outputBuilder.setPagination(value); + } + +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java new file mode 100644 index 000000000..c911100ef --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangProvider.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * ============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.File; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.YangFileProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.YangFilename; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.YangSchemaHttpServlet; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class TestYangProvider { + + private static final String TESTPATH = "cache/schema/"; + + + @BeforeClass + public static void init() { + Set<PosixFilePermission> perms; + FileAttribute<?> attr; + perms = EnumSet.noneOf(PosixFilePermission.class); + + perms.add(PosixFilePermission.OWNER_READ); + perms.add(PosixFilePermission.OWNER_WRITE); + perms.add(PosixFilePermission.OWNER_EXECUTE); + + attr = PosixFilePermissions.asFileAttribute(perms); + try { + Files.createDirectories(new File(TESTPATH).toPath(),attr); + new File(TESTPATH+new YangFilename("module1","2010-01-01").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module2","2010-01-01").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module2","2010-04-01").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module3","2010-01-01").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module4","2010-05-01").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module5","2010-01-11").getFilename()).createNewFile(); + new File(TESTPATH+new YangFilename("module6","2010-01-01").getFilename()).createNewFile(); + } catch (IOException | ParseException e) { + + } + } + @AfterClass + public static void deinit() { + try { + Files.walk(new File("cache").toPath()) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (IOException e) { + System.err.println(e); + } + } + @Test + public void testExisting() { + YangFileProvider provider= new YangFileProvider(TESTPATH); + assertTrue(provider.hasFileForModule("module1","2010-01-01")); + assertTrue(provider.hasFileForModule("module2")); + assertTrue(provider.hasFileForModule("module3")); + assertFalse(provider.hasFileForModule("module5","2010-01-01")); + } + @Test + public void testRevision() throws ParseException { + SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd"); + YangFileProvider provider= new YangFileProvider(TESTPATH); + YangFilename f1 = provider.getFileForModule("module1","2010-01-01"); + assertEquals("module1",f1.getModule()); + assertEquals(sdf.parse("2010-01-01"),f1.getRevision()); + YangFilename f2 = provider.getFileForModule("module2"); + assertEquals("module2",f2.getModule()); + assertEquals(sdf.parse("2010-04-01"),f2.getRevision()); + f2 = provider.getFileForModule("module2","2010-02-01"); + assertEquals("module2",f2.getModule()); + assertEquals(sdf.parse("2010-04-01"),f2.getRevision()); + YangFilename f3 = provider.getFileForModule("module3"); + assertEquals("module3",f3.getModule()); + assertEquals(sdf.parse("2010-01-01"),f3.getRevision()); + f3 = provider.getFileForModule("module3","2010-04-01"); + assertNull(f3); + } + @Test + public void testServlet() throws IOException, ServletException { + HelpYangSchemaHttpServlet servlet = new HelpYangSchemaHttpServlet(); + HttpServletRequest req = mock(HttpServletRequest.class); + HttpServletResponse resp = mock(HttpServletResponse.class); + + when(req.getRequestURI()).thenReturn("/yang-schema/module1"); + StringWriter out = new StringWriter(); + ServletOutputStream printOut = new ServletOutputStream() { + + @Override + public void write(int arg0) throws IOException { + out.write(arg0); + } + }; + when(resp.getOutputStream()).thenReturn(printOut); + servlet.doGet(req,resp); + verify(resp).setStatus(200); + verify(resp).setContentType("text/plain"); + + } + @Test + public void testServletBad() throws IOException, ServletException { + HelpYangSchemaHttpServlet servlet = new HelpYangSchemaHttpServlet(); + HttpServletRequest req = mock(HttpServletRequest.class); + HttpServletResponse resp = mock(HttpServletResponse.class); + + when(req.getRequestURI()).thenReturn("/yang-schema/module1/2020-01-01"); + StringWriter out = new StringWriter(); + ServletOutputStream printOut = new ServletOutputStream() { + + @Override + public void write(int arg0) throws IOException { + out.write(arg0); + } + }; + when(resp.getOutputStream()).thenReturn(printOut); + servlet.doGet(req,resp); + verify(resp).sendError(HttpServletResponse.SC_NOT_FOUND); + + } + @Test + public void testServletNear() throws IOException, ServletException { + HelpYangSchemaHttpServlet servlet = new HelpYangSchemaHttpServlet(); + HttpServletRequest req = mock(HttpServletRequest.class); + HttpServletResponse resp = mock(HttpServletResponse.class); + + when(req.getRequestURI()).thenReturn("/yang-schema/module2/2010-03-01"); + StringWriter out = new StringWriter(); + ServletOutputStream printOut = new ServletOutputStream() { + + @Override + public void write(int arg0) throws IOException { + out.write(arg0); + } + }; + when(resp.getOutputStream()).thenReturn(printOut); + servlet.doGet(req,resp); + verify(resp).setStatus(200); + verify(resp).setContentType("text/plain"); + + } + private static class HelpYangSchemaHttpServlet extends YangSchemaHttpServlet{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + super.doGet(req, resp); + } + } + + +} diff --git a/sdnr/wt/data-provider/provider/src/test/resources/log4j.properties b/sdnr/wt/data-provider/provider/src/test/resources/log4j.properties new file mode 100644 index 000000000..142663bd2 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/resources/log4j.properties @@ -0,0 +1,12 @@ +log4j.rootLogger=INFO, out + +log4j.logger.org.apache.camel.impl.converter=WARN +log4j.logger.org.apache.camel.management=WARN +log4j.logger.org.apache.camel.impl.DefaultPackageScanClassResolver=WARN +log4j.logger.org.springframework=ERROR + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + diff --git a/sdnr/wt/data-provider/provider/src/test/resources/log4j2.xml b/sdnr/wt/data-provider/provider/src/test/resources/log4j2.xml new file mode 100644 index 000000000..164e93f54 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/resources/log4j2.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration package="log4j.test" + status="WARN"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> + </Console> + </Appenders> + <Loggers> + <Logger name="log4j.test.Log4jTest" level="debug"> + <AppenderRef ref="Console"/> + </Logger> + <Root level="trace"> + <AppenderRef ref="Console"/> + </Root> + </Loggers> +</Configuration>
\ No newline at end of file diff --git a/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties b/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..a2f1e7e76 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.defaultLogLevel=debug +org.slf4j.simpleLogger.showDateTime=true +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z +#org.slf4j.simpleLogger.showThreadName=true +org.slf4j.simpleLogger.showLogName=true +org.slf4j.simpleLogger.showShortLogName=false
\ No newline at end of file diff --git a/sdnr/wt/data-provider/provider/src/test/resources/test.properties b/sdnr/wt/data-provider/provider/src/test/resources/test.properties new file mode 100644 index 000000000..de49c5893 --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/resources/test.properties @@ -0,0 +1,55 @@ +[dcae] +dcaeUserCredentials=admin:admin +dcaeUrl=off +dcaeHeartbeatPeriodSeconds=120 +dcaeTestCollector=no + +[aots] +userPassword=passwd +soapurladd=off +soapaddtimeout=10 +soapinqtimeout=20 +userName=user +inqtemplate=inqreq.tmpl.xml +assignedto=userid +addtemplate=addreq.tmpl.xml +severitypassthrough=critical,major,minor,warning +systemuser=user +prt-offset=1200 +soapurlinq=off +#smtpHost= +#smtpPort= +#smtpUsername= +#smtpPassword= +#smtpSender= +#smtpReceivers= + +[es] +esCluster=sendateodl5 +#time limit to keep increasing data in database [in seconds] +#60*60*24*30 (30days) +esArchiveLimit=2592000 +#folder where removed data will be stored +esArchiveFolder=./backup +#interval to archive database [in seconds] +#60*60*24 (1day) +esArchiveInterval=86400 + +[aai] +#keep comment +aaiHeaders=["X-TransactionId: 9999"] +aaiUrl=http://localhost:81 +aaiUserCredentials=AAI:AAI +aaiDeleteOnMountpointRemove=false +aaiTrustAllCerts=false +aaiApiVersion=aai/v13 +aaiPropertiesFile=aaiclient.properties +aaiApplicationId=SDNR +aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12 +aaiPcks12ClientCertPassphrase=adminadmin +aaiClientConnectionTimeout=30000 + +[pm] +pmCluster=sendateodl5 +pmEnabled=true + |