diff options
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test')
18 files changed, 1455 insertions, 1517 deletions
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java index 372435343..f147e8724 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestAbout.java @@ -43,92 +43,96 @@ 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); - } - - } + 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 index ce3ff6694..0294c6e50 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -122,8 +122,8 @@ public class TestCRUDforDatabase { private static ElasticSearchDataProvider dbProvider; private static HtDatabaseClient dbRawProvider; - public static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer - .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")) }; + public 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 { @@ -149,40 +149,49 @@ public class TestCRUDforDatabase { 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); + 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(); + 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()); + 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()); + 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 + @Test public void testMediatorServer() { final String NAME = "ms1"; final String URL = "http://11.23.45.55:4599"; @@ -229,8 +238,8 @@ public class TestCRUDforDatabase { System.out.println(data); // ==UPDATE============================ System.out.println("try to update entry"); - UpdateMediatorServerInput updateInput = new UpdateMediatorServerInputBuilder().setId(dbId2).setName(NAME2) - .setUrl(URL2).build(); + UpdateMediatorServerInput updateInput = + new UpdateMediatorServerInputBuilder().setId(dbId2).setName(NAME2).setUrl(URL2).build(); UpdateMediatorServerOutputBuilder updateOutput = null; try { updateOutput = dbProvider.updateMediatorServer(updateInput); @@ -274,7 +283,7 @@ public class TestCRUDforDatabase { assertEquals("delete not verifiied", 0, data.size()); } - @Test + @Test public void testNetworkElementConnectionCurrent() { System.out.println("networkElementConnection test start"); @@ -314,10 +323,10 @@ public class TestCRUDforDatabase { .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(); + 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()); @@ -331,7 +340,8 @@ public class TestCRUDforDatabase { final String url2 = "10.5.10.2"; final long port2 = 5960; - UpdateNetworkElementConnectionInput updateInput = new UpdateNetworkElementConnectionInputBuilder().setId(dbId).setHost(url2).setPort(port2).setIsRequired(false).build(); + UpdateNetworkElementConnectionInput updateInput = new UpdateNetworkElementConnectionInputBuilder().setId(dbId) + .setHost(url2).setPort(port2).setIsRequired(false).build(); UpdateNetworkElementConnectionOutputBuilder updateOutput = null; try { updateOutput = dbProvider.updateNetworkElementConnection(updateInput); @@ -373,12 +383,12 @@ public class TestCRUDforDatabase { // ==DELETE============================ System.out.println("Try delete..."); - DeleteNetworkElementConnectionInput deleteInput = new DeleteNetworkElementConnectionInputBuilder().setId(dbId) - .build(); + DeleteNetworkElementConnectionInput deleteInput = + new DeleteNetworkElementConnectionInputBuilder().setId(dbId).build(); try { dbProvider.deleteNetworkElementConnection(deleteInput); } catch (Exception e) { - fail("problem deleting "+e.getMessage()); + fail("problem deleting " + e.getMessage()); } readInput = new ReadNetworkElementConnectionListInputBuilder() @@ -390,7 +400,7 @@ public class TestCRUDforDatabase { } - @Test + @Test public void testMaintenance() { System.out.println("Starting Maintenance tests..."); @@ -408,8 +418,8 @@ public class TestCRUDforDatabase { final boolean isActive = true; CreateMaintenanceOutputBuilder create = null; - CreateMaintenanceInput input = new CreateMaintenanceInputBuilder().setNodeId(nodeId).setActive(isActive) - .build(); + CreateMaintenanceInput input = + new CreateMaintenanceInputBuilder().setNodeId(nodeId).setActive(isActive).build(); String dbId = null; try { create = dbProvider.createMaintenance(input); @@ -429,8 +439,8 @@ public class TestCRUDforDatabase { .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(); + 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); @@ -443,8 +453,8 @@ public class TestCRUDforDatabase { final String nodeId2 = "Name2"; final boolean isActive2 = false; - UpdateMaintenanceInput updateInput = new UpdateMaintenanceInputBuilder().setId(dbId).setNodeId(nodeId2) - .setActive(isActive2).build(); + UpdateMaintenanceInput updateInput = + new UpdateMaintenanceInputBuilder().setId(dbId).setNodeId(nodeId2).setActive(isActive2).build(); UpdateMaintenanceOutputBuilder updateResult = null; try { updateResult = dbProvider.updateMaintenance(updateInput); @@ -483,7 +493,9 @@ public class TestCRUDforDatabase { 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); + 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"); @@ -500,8 +512,8 @@ public class TestCRUDforDatabase { 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(); + 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()); @@ -509,17 +521,18 @@ public class TestCRUDforDatabase { assertEquals("Critical", data.get(0).getSeverity().toString()); assertEquals("s1", data.get(0).getNodeId()); - //== UPDATE ================================ + //== UPDATE ================================ System.out.println("try to update entry"); - dbRawProvider.doUpdateOrCreate(Entity.Faultlog.getName(), "1", "{'problem': 'CableLOS', 'severity': 'Major', 'node-id': 'test4657-78'}"); + 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 ================================ + //== VERIFY UPDATE ================================ readResult = dbProvider.readFaultLogList(readinput); data = readResult.getData(); @@ -544,7 +557,7 @@ public class TestCRUDforDatabase { assertEquals("Major", data.get(0).getSeverity().toString()); assertEquals("test4657-78", data.get(0).getNodeId()); - //== DELETE ================================ + //== DELETE ================================ System.out.println("try to clear entry"); try { @@ -553,9 +566,10 @@ public class TestCRUDforDatabase { fail("problem deleting entry: " + e.getMessage()); } - //== VERIFY DELETE =========================== + //== VERIFY DELETE =========================== System.out.println("verify entries deleted"); - readResult = dbProvider.readFaultLogList(new ReadFaultlogListInputBuilder().setPagination(getPagination(20, 1)).build()); + readResult = dbProvider + .readFaultLogList(new ReadFaultlogListInputBuilder().setPagination(getPagination(20, 1)).build()); data = readResult.getData(); assertEquals(0, data.size()); } @@ -563,12 +577,14 @@ public class TestCRUDforDatabase { @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); + 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..."); + System.out.println("Trying to read..."); ReadFaultcurrentListInput readinput = new ReadFaultcurrentListInputBuilder() @@ -583,8 +599,8 @@ public class TestCRUDforDatabase { 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(); + 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); @@ -601,12 +617,8 @@ public class TestCRUDforDatabase { // ==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 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); @@ -656,23 +668,21 @@ public class TestCRUDforDatabase { // ==CLEAR================================ System.out.println("Clear before test"); - try { - dbRawProvider.doRemove(Entity.Connectionlog.getName(), QueryBuilders.matchAllQuery()); - } catch (Exception e) { - fail("problem deleting: " + e.getMessage()); - } + 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" + - "}"; + 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); @@ -693,8 +703,8 @@ public class TestCRUDforDatabase { 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(); + 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()); @@ -728,46 +738,42 @@ public class TestCRUDforDatabase { assertEquals("Connected", data.get(0).getStatus().toString()); assertEquals("sim2230", data.get(0).getNodeId()); - //== DELETE ================================ + //== DELETE ================================ - System.out.println("try to clear entry"); - try { - dbRawProvider.doRemove(Entity.Connectionlog.getName(), dbId); - } catch (Exception e) { - fail("problem deleting entry: " + e.getMessage()); - } + 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()); + //== 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 + @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()); - } + 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" + - "}"; + 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); @@ -779,86 +785,83 @@ public class TestCRUDforDatabase { .setPagination(getPagination(20, 1)).build(); ReadEventlogListOutputBuilder readResult = null; try { - readResult = dbProvider.readEventlogList(readinput); + 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()); + 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()); - } + 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()); + 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()); + data = readResult.getData(); + assertEquals(0, data.size()); } - @Test + @Test public void testInventory() { - System.out.println("Test inventory starting..."); + 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()); - } + // ==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); + 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() + 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); + readResult = dbProvider.readInventoryList(readinput); } catch (Exception e) { - fail("Problem reading inventory list"+e.getMessage()); + 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()); + 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()); @@ -869,15 +872,12 @@ public class TestCRUDforDatabase { System.out.println(data.get(0).getDate()); // ==UPDATE============================ - String updatedDbId=null; + 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" + - "}"; + 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); @@ -886,12 +886,12 @@ public class TestCRUDforDatabase { readResult = dbProvider.readInventoryList(readinput); } catch (Exception e) { - fail("Problem reading inventory list"+e.getMessage()); + fail("Problem reading inventory list" + e.getMessage()); } data = readResult.getData(); - assertEquals(1,data.size()); + 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()); @@ -899,10 +899,10 @@ public class TestCRUDforDatabase { 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)); + 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============================ @@ -913,50 +913,50 @@ public class TestCRUDforDatabase { fail("problem deleting: " + e.getMessage()); } - // ==VERIFY DELETE ============================ + // ==VERIFY DELETE ============================ try { - readResult = dbProvider.readInventoryList(readinput); + readResult = dbProvider.readInventoryList(readinput); - } catch (Exception e) { - fail("Problem reading inventory list"+e.getMessage()); - } + } catch (Exception e) { + fail("Problem reading inventory list" + e.getMessage()); + } - data = readResult.getData(); - assertEquals(0,data.size()); + data = readResult.getData(); + assertEquals(0, data.size()); } - @Test - public void test15MinPerformanceReadLtpListWithoutNodeIdSetThrowsException() { + @Test + public void test15MinPerformanceReadLtpListWithoutNodeIdSetThrowsException() { - System.out.println("Reading 15m ltp list without node id filter set throws an exception test start..."); + 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()); - } + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } - System.out.println("create entries..."); + 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("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"); + 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..."); + System.out.println("trying to read, should throw exception..."); - ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder() - .setPagination(getPagination(20, 1)).build(); + ReadPmdata15mLtpListInput readLtp = + new ReadPmdata15mLtpListInputBuilder().setPagination(getPagination(20, 1)).build(); - ReadPmdata15mLtpListOutputBuilder readltpResult = null; + ReadPmdata15mLtpListOutputBuilder readltpResult = null; - try { + try { readltpResult = dbProvider.readPmdata15mLtpList(readLtp); fail("No exception thrown!"); } catch (Exception e) { @@ -965,299 +965,302 @@ public class TestCRUDforDatabase { assertEquals("no nodename in filter found ", e.getMessage()); } - assertNull(readltpResult); + assertNull(readltpResult); - //== DELETE ================================ + //== 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()); - } + 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(); + //== 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()); - } + assertEquals(0, data.size()); + } - @Test - public void test15MinPerformanceData() { + @Test + public void test15MinPerformanceData() { // == CLEAR BEFORE TESTS ============================ - System.out.println("Test 15 min performance..."); + System.out.println("Test 15 min performance..."); - try { - dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); - } catch (Exception e) { - fail("problem deleting: " + e.getMessage()); - } + try { + dbRawProvider.doRemove(Entity.Historicalperformance15min.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } // == CREATE ============================ - System.out.println("create entries..."); + 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("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"); + 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..."); + 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(); + ReadPmdata15mListInput read = new ReadPmdata15mListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); - ReadPmdata15mListOutputBuilder readResult = null; + ReadPmdata15mListOutputBuilder readResult = null; - try { - readResult = dbProvider.readPmdata15mList(read); + 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(); + 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()); + assertNotNull(data); + assertEquals(2, data.size()); - System.out.println("read ltp entries with node name set..."); + 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(); + ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); - ReadPmdata15mLtpListOutputBuilder readltpResult = null; + ReadPmdata15mLtpListOutputBuilder readltpResult = null; - try { - readltpResult = dbProvider.readPmdata15mLtpList(readLtp); - } catch (Exception e) { - fail("Problem reading 15m ltp data"); - } + try { + readltpResult = dbProvider.readPmdata15mLtpList(readLtp); + } catch (Exception e) { + fail("Problem reading 15m ltp data"); + } - List<String> dataLtp = readltpResult.getData(); + 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")); + 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..."); + System.out.println("read device entries..."); - ReadPmdata15mDeviceListInput readDevices = new ReadPmdata15mDeviceListInputBuilder() - .setPagination(getPagination(20, 1)).build(); + ReadPmdata15mDeviceListInput readDevices = + new ReadPmdata15mDeviceListInputBuilder().setPagination(getPagination(20, 1)).build(); - ReadPmdata15mDeviceListOutputBuilder readDeviceResult = null; + ReadPmdata15mDeviceListOutputBuilder readDeviceResult = null; - try { - readDeviceResult = dbProvider.readPmdata15mDeviceList(readDevices); - } catch (Exception e) { - fail("Problem reading 15m device data"); - } + try { + readDeviceResult = dbProvider.readPmdata15mDeviceList(readDevices); + } catch (Exception e) { + fail("Problem reading 15m device data"); + } - List<String> dataDevice = readDeviceResult.getData(); + List<String> dataDevice = readDeviceResult.getData(); - assertNotNull(dataDevice); - assertEquals(2, dataDevice.size()); - assertTrue(dataDevice.contains("a2")); - assertTrue(dataDevice.contains("a3")); + assertNotNull(dataDevice); + assertEquals(2, dataDevice.size()); + assertTrue(dataDevice.contains("a2")); + assertTrue(dataDevice.contains("a3")); - //== DELETE ================================ + //== 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()); - } + 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()); + //== 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..."); + @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()); - } + 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"); + 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"); + 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..."); + System.out.println("read all list entries..."); - ReadPmdata24hListInput read = new ReadPmdata24hListInputBuilder() - .setPagination(getPagination(20, 1)).build(); + ReadPmdata24hListInput read = new ReadPmdata24hListInputBuilder().setPagination(getPagination(20, 1)).build(); - ReadPmdata24hListOutputBuilder readResult = null; + ReadPmdata24hListOutputBuilder readResult = null; - try { - readResult = dbProvider.readPmdata24hList(read); + 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(); + 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()); + assertNotNull(data); + assertEquals(6, data.size()); - System.out.println("filter list entries..."); + 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(); + read = new ReadPmdata24hListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); - readResult = null; + readResult = null; - try { - readResult = dbProvider.readPmdata24hList(read); + try { + readResult = dbProvider.readPmdata24hList(read); } catch (Exception e) { fail("Problem reading 24h data"); } - data = readResult.getData(); + data = readResult.getData(); - assertNotNull(data); - assertEquals(3, data.size()); + assertNotNull(data); + assertEquals(3, data.size()); - System.out.println("read ltp entries with node name set..."); + 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(); + ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder() + .setFilter(Arrays.asList(new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setPagination(getPagination(20, 1)).build(); - ReadPmdata24hLtpListOutputBuilder readltpResult = null; + ReadPmdata24hLtpListOutputBuilder readltpResult = null; - try { - readltpResult = dbProvider.readPmdata24hLtpList(readLtp); - } catch (Exception e) { - fail("Problem reading 24h ltp data"); - } + try { + readltpResult = dbProvider.readPmdata24hLtpList(readLtp); + } catch (Exception e) { + fail("Problem reading 24h ltp data"); + } - List<String> dataLtp = readltpResult.getData(); + 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")); + 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..."); + System.out.println("read device entries..."); - ReadPmdata24hDeviceListInput readDevices = new ReadPmdata24hDeviceListInputBuilder() - .setPagination(getPagination(20, 1)).build(); + ReadPmdata24hDeviceListInput readDevices = + new ReadPmdata24hDeviceListInputBuilder().setPagination(getPagination(20, 1)).build(); - ReadPmdata24hDeviceListOutputBuilder readDeviceResult = null; + ReadPmdata24hDeviceListOutputBuilder readDeviceResult = null; - try { - readDeviceResult = dbProvider.readPmdata24hDeviceList(readDevices); - } catch (Exception e) { - fail("Problem reading 24h device data"); - } + try { + readDeviceResult = dbProvider.readPmdata24hDeviceList(readDevices); + } catch (Exception e) { + fail("Problem reading 24h device data"); + } - List<String> dataDevice = readDeviceResult.getData(); + List<String> dataDevice = readDeviceResult.getData(); - assertNotNull(dataDevice); - assertEquals(2, dataDevice.size()); - assertTrue(dataDevice.contains("a2")); - assertTrue(dataDevice.contains("a3")); + assertNotNull(dataDevice); + assertEquals(2, dataDevice.size()); + assertTrue(dataDevice.contains("a2")); + assertTrue(dataDevice.contains("a3")); - // == UPDATE ============================== + // == UPDATE ============================== - boolean success = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); - assertTrue("update dbentry not succeeded",success); - try { - readltpResult = dbProvider.readPmdata24hLtpList(readLtp); + boolean success = dbRawProvider.doUpdate(Entity.Historicalperformance24h.getName(), + "{'uuid-interface':'LTP-TEST-MWP-097'}", QueryBuilders.termQuery("_id", aDbId)); + assertTrue("update dbentry not succeeded", success); + try { + readltpResult = dbProvider.readPmdata24hLtpList(readLtp); } catch (Exception e) { fail("Problem reading 24h ltp data"); } - // == VERIFY UPDATE ============================== + // == VERIFY UPDATE ============================== - dataLtp = readltpResult.getData(); + 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")); + 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 =========================== + //== 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()); - } + 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()); - } + //== 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...\"..."); + @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()); - } + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } - System.out.println("create entries..."); + 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"); + 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"); + 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..."); + System.out.println("trying to read, should throw exception..."); - ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder() - .setPagination(getPagination(20, 1)).build(); + ReadPmdata24hLtpListInput readLtp = + new ReadPmdata24hLtpListInputBuilder().setPagination(getPagination(20, 1)).build(); - ReadPmdata24hLtpListOutputBuilder readltpResult = null; + ReadPmdata24hLtpListOutputBuilder readltpResult = null; - try { + try { readltpResult = dbProvider.readPmdata24hLtpList(readLtp); fail("No exception thrown!"); } catch (Exception e) { @@ -1266,14 +1269,14 @@ public class TestCRUDforDatabase { assertEquals("no nodename in filter found ", e.getMessage()); } - assertNull(readltpResult); + assertNull(readltpResult); - try { - dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); - } catch (Exception e) { - fail("problem deleting: " + e.getMessage()); - } - } + try { + dbRawProvider.doRemove(Entity.Historicalperformance24h.getName(), QueryBuilders.matchAllQuery()); + } catch (Exception e) { + fail("problem deleting: " + e.getMessage()); + } + } @Test public void testUrlEncoding() { @@ -1294,7 +1297,9 @@ public class TestCRUDforDatabase { 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); + 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); } @@ -1302,44 +1307,47 @@ public class TestCRUDforDatabase { 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); + 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=========================== + // ==READ=========================== System.out.println("Trying to read..."); - String readResult = null; - try { - readResult = dbRawProvider.doReadJsonData(Entity.Faultcurrent.getName(), dbId); + String readResult = null; + try { + readResult = dbRawProvider.doReadJsonData(Entity.Faultcurrent.getName(), dbId); - } catch (Exception e) { - fail("Fault log not read: " + e.getMessage()); - } + } 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\"}"; + 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); + System.out.println(readResult); + assertNotNull(readResult); + assertEquals(expectedDbResult, readResult); - SearchResult<SearchHit> searchResult = dbRawProvider.doReadAllJsonData(Entity.Faultcurrent.getName()); - assertNotNull(searchResult); + SearchResult<SearchHit> searchResult = dbRawProvider.doReadAllJsonData(Entity.Faultcurrent.getName()); + assertNotNull(searchResult); - List<SearchHit> hits = searchResult.getHits(); + List<SearchHit> hits = searchResult.getHits(); - assertNotNull(hits); - assertEquals(1, searchResult.getTotal()); - assertEquals(expectedDbResult, hits.get(0).getSourceAsString()); + 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()); + //== 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()); @@ -1348,25 +1356,20 @@ public class TestCRUDforDatabase { @Test public void testOutputCamelCase() { - try { - String jsonString="{\n" + - "\"timestamp\": \"2020-02-20T09:31:22.3Z\",\n" + - "\"object-id\": \"LP-MWPS-RADIO\",\n" + - "\"severity\": \"Critical\",\n" + - "\"counter\": 10,\n" + - "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog\",\n" + - "\"source-type\": \"Netconf\",\n" + - "\"node-id\": \"sim4\",\n" + - "\"problem\": \"signalIsLost\"\n" + - "}"; - YangToolsMapper yangtoolsMapper = new YangToolsMapper(); - FaultlogEntity log = yangtoolsMapper.readValue( jsonString, Faultlog.class ); - System.out.println(log ); - System.out.println(yangtoolsMapper.writeValueAsString(log)); - } catch (IOException e) { - fail(e.getMessage()); - } - + try { + String jsonString = "{\n" + "\"timestamp\": \"2020-02-20T09:31:22.3Z\",\n" + + "\"object-id\": \"LP-MWPS-RADIO\",\n" + "\"severity\": \"Critical\",\n" + "\"counter\": 10,\n" + + "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog\",\n" + + "\"source-type\": \"Netconf\",\n" + "\"node-id\": \"sim4\",\n" + "\"problem\": \"signalIsLost\"\n" + + "}"; + YangToolsMapper yangtoolsMapper = new YangToolsMapper(); + FaultlogEntity log = yangtoolsMapper.readValue(jsonString, Faultlog.class); + System.out.println(log); + System.out.println(yangtoolsMapper.writeValueAsString(log)); + } catch (IOException e) { + fail(e.getMessage()); + } + } private Pagination getPagination(long pageSize, int page) { @@ -1374,7 +1377,8 @@ public class TestCRUDforDatabase { } - private String clearAndCreatefaultEntity(String initialDbId, String entityType, String implementedInterface, SeverityType severity) { + private String clearAndCreatefaultEntity(String initialDbId, String entityType, String implementedInterface, + SeverityType severity) { // ==CLEAR BEFORE TEST============================ System.out.println("try to clear entry"); try { @@ -1387,23 +1391,19 @@ public class TestCRUDforDatabase { return createFaultEntity(initialDbId, entityType, implementedInterface, severity); } - private String createFaultEntity(String initialDbId, String entityType, String implementedInterface, SeverityType severity) { - // ==CREATE============================ + 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" + - "}"); + 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" + "}"); @@ -1414,65 +1414,31 @@ public class TestCRUDforDatabase { 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)) { + 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 { + } 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 index 1b5e1afa7..c0234bfce 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfig.java @@ -44,15 +44,16 @@ public class TestConfig { @After @Before public void afterAndBefore() { - File f=new File(TESTFILENAME); - if(f.exists()) { + File f = new File(TESTFILENAME); + if (f.exists()) { LOG.info("Remove {}", f.getAbsolutePath()); f.delete(); } } + @Test public void test() { - ConfigurationFileRepresentation configuration=new ConfigurationFileRepresentation(TESTFILENAME); + ConfigurationFileRepresentation configuration = new ConfigurationFileRepresentation(TESTFILENAME); setSDNRDBURLEnv(); EsConfig esConfig = new EsConfig(configuration); LOG.info("Defaultconfiguration: {}", esConfig.toString()); @@ -61,19 +62,21 @@ public class TestConfig { assertEquals("sdnrdb", esConfig.getHosts()[0].hostname); } + public static void setSDNRDBURLEnv() { - setEnv("SDNRDBURL","http://sdnrdb:9200"); + setEnv("SDNRDBURL", "http://sdnrdb:9200"); + } + + public static void setEnv(String key, String value) { + try { + Map<String, String> env = System.getenv(); + Class<?> cl = env.getClass(); + Field field = cl.getDeclaredField("m"); + field.setAccessible(true); + Map<String, String> writableEnv = (Map<String, String>) field.get(env); + writableEnv.put(key, value); + } catch (Exception e) { + throw new IllegalStateException("Failed to set environment variable", e); + } } - public static void setEnv(String key, String value) { - try { - Map<String, String> env = System.getenv(); - Class<?> cl = env.getClass(); - Field field = cl.getDeclaredField("m"); - field.setAccessible(true); - Map<String, String> writableEnv = (Map<String, String>) field.get(env); - writableEnv.put(key, value); - } catch (Exception e) { - throw new IllegalStateException("Failed to set environment variable", e); - } - } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java index 30b1003c2..d06486550 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestConfiguration.java @@ -39,14 +39,14 @@ public class TestConfiguration { System.out.println("Configuration file " + CONFIGURATIONTESTFILE); File testConfigurationFile = ResourceFileLoader.getFile(this, CONFIGURATIONTESTFILE); - System.out.println("Located at: "+testConfigurationFile.getAbsolutePath()); + 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()); + System.out.println("ES config getArchiveLifetimeSeconds: " + esConfig1.getArchiveLifetimeSeconds()); // fail("Not yet implemented"); 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 index f68a6e8f3..a4b284e4f 100644 --- 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 @@ -39,172 +39,121 @@ 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); - } + 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/TestDataTreeSerialization.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java index 54b2dc00d..60a2c50e4 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataTreeSerialization.java @@ -29,5 +29,5 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; */ public class TestDataTreeSerialization { - //YangToolsMapper + //YangToolsMapper } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java index c528e3552..308bbf663 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -70,251 +70,251 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro * */ public class TestEventService { - private static ElasticSearchDataProvider dbProvider; - private static HtDatabaseClient dbRawProvider; - private static HtDatabaseEventsService service = null; + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static HtDatabaseEventsService service = null; - private static final String NODEID = "node1"; - private static final String NODEID2 = "node2"; - private static final String OBJECTREFID1 = "objid1"; - private static final String OBJECTREFID2 = "objid2"; + private static final String NODEID = "node1"; + private static final String NODEID2 = "node2"; + private static final String OBJECTREFID1 = "objid1"; + private static final String OBJECTREFID2 = "objid2"; - @BeforeClass - public static void init() throws Exception { + @BeforeClass + public static void init() throws Exception { - dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); - dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); - try { - service = new HtDatabaseEventsService(dbRawProvider, dbProvider); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } + try { + service = new HtDatabaseEventsService(dbRawProvider, dbProvider); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } - @Test - public void testClearFaultsCurrent() { + @Test + public void testClearFaultsCurrent() { - service.clearFaultsCurrentOfNode(NODEID); - service.clearFaultsCurrentOfNode(NODEID2); + service.clearFaultsCurrentOfNode(NODEID); + service.clearFaultsCurrentOfNode(NODEID2); - List<String> nodeIds = service.getAllNodesWithCurrentAlarms(); - if (nodeIds.size() > 0) { - for (String nodeId : nodeIds) { - service.clearFaultsCurrentOfNode(nodeId); - } - } - service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abc", SeverityType.Major)); - service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abcde", SeverityType.Major)); - service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.Major)); - service.updateFaultCurrent(createFault(NODEID2, OBJECTREFID2, "abcde", SeverityType.Major)); - nodeIds = service.getAllNodesWithCurrentAlarms(); - assertTrue(nodeIds.size() == 2); - service.clearFaultsCurrentOfNodeWithObjectId(NODEID, OBJECTREFID1); - nodeIds = service.getAllNodesWithCurrentAlarms(); - assertTrue(nodeIds.size() == 2); - service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.NonAlarmed)); - nodeIds = service.getAllNodesWithCurrentAlarms(); - assertTrue(nodeIds.size() == 1); - } + List<String> nodeIds = service.getAllNodesWithCurrentAlarms(); + if (nodeIds.size() > 0) { + for (String nodeId : nodeIds) { + service.clearFaultsCurrentOfNode(nodeId); + } + } + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abc", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID1, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.Major)); + service.updateFaultCurrent(createFault(NODEID2, OBJECTREFID2, "abcde", SeverityType.Major)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.clearFaultsCurrentOfNodeWithObjectId(NODEID, OBJECTREFID1); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 2); + service.updateFaultCurrent(createFault(NODEID, OBJECTREFID2, "abcde", SeverityType.NonAlarmed)); + nodeIds = service.getAllNodesWithCurrentAlarms(); + assertTrue(nodeIds.size() == 1); + } - private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, - SeverityType severity) { - return createFault(nodeId, objectRefId, problem, severity, NetconfTimeStampImpl.getConverter().getTimeStamp()); - } + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity) { + return createFault(nodeId, objectRefId, problem, severity, NetconfTimeStampImpl.getConverter().getTimeStamp()); + } - /** - * @param nODENAME - * @param problem - * @param ts - * @param severity - * @return - */ - private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, - SeverityType severity, DateAndTime ts) { - return new FaultcurrentBuilder().setNodeId(nodeId).setObjectId(objectRefId).setTimestamp(ts) - .setSeverity(severity).setProblem(problem).build(); - } + /** + * @param nODENAME + * @param problem + * @param ts + * @param severity + * @return + */ + private static FaultcurrentEntity createFault(String nodeId, String objectRefId, String problem, + SeverityType severity, DateAndTime ts) { + return new FaultcurrentBuilder().setNodeId(nodeId).setObjectId(objectRefId).setTimestamp(ts) + .setSeverity(severity).setProblem(problem).build(); + } - @Test - public void testIndexClean() { - Date now = new Date(); - service.doIndexClean(now); - clearDbEntity(Entity.Eventlog); - clearDbEntity(Entity.Faultlog); - TestCRUDforDatabase.trySleep(1000); - service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "abc", 1)); - service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "avasvas", 2)); + @Test + public void testIndexClean() { + Date now = new Date(); + service.doIndexClean(now); + clearDbEntity(Entity.Eventlog); + clearDbEntity(Entity.Faultlog); + TestCRUDforDatabase.trySleep(1000); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "abc", 1)); + service.writeEventLog(createEventLog(NODEID, OBJECTREFID1, "aaa", "avasvas", 2)); - service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 1)); - service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 2)); - service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); - TestCRUDforDatabase.trySleep(100); - now = new Date(); - int numOlds = service.getNumberOfOldObjects(now); - assertEquals(5, numOlds); - TestCRUDforDatabase.trySleep(100); - service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); - service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 5)); - service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 6)); - numOlds = service.getNumberOfOldObjects(now); - assertEquals(5, numOlds); - now = new Date(); - numOlds = service.getNumberOfOldObjects(now); - assertEquals(8, numOlds); - service.doIndexClean(now); - numOlds = service.getNumberOfOldObjects(now); - assertEquals(0, numOlds); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 1)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 2)); + service.writeFaultLog(createFaultLog(NODEID2, OBJECTREFID2, "problem", SeverityType.Major, 1)); + TestCRUDforDatabase.trySleep(100); + now = new Date(); + int numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + TestCRUDforDatabase.trySleep(100); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 3)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.NonAlarmed, 5)); + service.writeFaultLog(createFaultLog(NODEID, OBJECTREFID2, "problem", SeverityType.Major, 6)); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(5, numOlds); + now = new Date(); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(8, numOlds); + service.doIndexClean(now); + numOlds = service.getNumberOfOldObjects(now); + assertEquals(0, numOlds); - } + } - @Test - public void testPm() { - final String IFNAME1 = "if1"; - final String SCNID1 = "scn1"; - List<PmdataEntity> list = Arrays.asList(createPmData(NODEID, IFNAME1, SCNID1), - createPmData(NODEID, IFNAME1, SCNID1), createPmData(NODEID, IFNAME1, SCNID1), - createPmData(NODEID, IFNAME1, SCNID1) + @Test + public void testPm() { + final String IFNAME1 = "if1"; + final String SCNID1 = "scn1"; + List<PmdataEntity> list = + Arrays.asList(createPmData(NODEID, IFNAME1, SCNID1), createPmData(NODEID, IFNAME1, SCNID1), + createPmData(NODEID, IFNAME1, SCNID1), createPmData(NODEID, IFNAME1, SCNID1) - ); - service.doWritePerformanceData(list); - } + ); + service.doWritePerformanceData(list); + } - /** - * @param ifname - * @param ifUuid - * @param scannerId - * @param nodename3 - * @return - */ - private static PmdataEntity createPmData(String nodeId, String ifUuid, String scannerId) { - return new PmdataEntityBuilder().setNodeName(nodeId).setGranularityPeriod(GranularityPeriodType.Period15Min) - .setUuidInterface(ifUuid).setScannerId(scannerId).setLayerProtocolName("NETCONF") - .setPerformanceData(null).setSuspectIntervalFlag(true) - .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).build(); - } + /** + * @param ifname + * @param ifUuid + * @param scannerId + * @param nodename3 + * @return + */ + private static PmdataEntity createPmData(String nodeId, String ifUuid, String scannerId) { + return new PmdataEntityBuilder().setNodeName(nodeId).setGranularityPeriod(GranularityPeriodType.Period15Min) + .setUuidInterface(ifUuid).setScannerId(scannerId).setLayerProtocolName("NETCONF") + .setPerformanceData(null).setSuspectIntervalFlag(true) + .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).build(); + } - @Test - public void testNeConnection() { - service.removeNetworkConnection(NODEID); - service.removeNetworkConnection(NODEID2); + @Test + public void testNeConnection() { + service.removeNetworkConnection(NODEID); + service.removeNetworkConnection(NODEID2); - clearDbEntity(Entity.NetworkelementConnection); - List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections(); - assertEquals(0, nes.size()); - service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); - service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2); - nes = service.getNetworkElementConnections(); - assertEquals(2, nes.size()); - service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless), - NODEID); - nes = service.getNetworkElementConnections(); - assertEquals(2, nes.size()); - boolean found = false; - for (NetworkElementConnectionEntity ne : nes) { - if (NODEID.equals(ne.getNodeId()) && ne.getDeviceType() == NetworkElementDeviceType.Wireless) { - found = true; - } - } - assertTrue(found); + clearDbEntity(Entity.NetworkelementConnection); + List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections(); + assertEquals(0, nes.size()); + service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); + service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + service.updateNetworkConnectionDeviceType(createNeConnection(NODEID, NetworkElementDeviceType.Wireless), + NODEID); + nes = service.getNetworkElementConnections(); + assertEquals(2, nes.size()); + boolean found = false; + for (NetworkElementConnectionEntity ne : nes) { + if (NODEID.equals(ne.getNodeId()) && ne.getDeviceType() == NetworkElementDeviceType.Wireless) { + found = true; + } + } + assertTrue(found); - } + } - @Test - public void testConnectionLog() { - clearDbEntity(Entity.Connectionlog); - service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); - service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); - assertEquals(2, getDbEntityEntries(Entity.Connectionlog).getTotal()); - } + @Test + public void testConnectionLog() { + clearDbEntity(Entity.Connectionlog); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + service.writeConnectionLog(createConnectionLog(NODEID, ConnectionLogStatus.Mounted)); + assertEquals(2, getDbEntityEntries(Entity.Connectionlog).getTotal()); + } - /** - * @param nodeId - * @param status - * @return - */ - private static ConnectionlogEntity createConnectionLog(String nodeId, ConnectionLogStatus status) { - return new ConnectionlogBuilder().setNodeId(nodeId) - .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setStatus(status).build(); - } + /** + * @param nodeId + * @param status + * @return + */ + private static ConnectionlogEntity createConnectionLog(String nodeId, ConnectionLogStatus status) { + return new ConnectionlogBuilder().setNodeId(nodeId) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setStatus(status).build(); + } - @Test - public void testInventory() { - clearDbEntity(Entity.Inventoryequipment); - service.writeInventory(createEquipment(NODEID, "uuid1")); - service.writeInventory(createEquipment(NODEID, "uuid2")); - service.writeInventory(createEquipment(NODEID2, "uuid3")); - service.writeInventory(createEquipment(NODEID2, "uuid4")); - service.writeInventory(createEquipment(NODEID2, "uuid5")); - assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal()); - } + @Test + public void testInventory() { + clearDbEntity(Entity.Inventoryequipment); + service.writeInventory(createEquipment(NODEID, "uuid1")); + service.writeInventory(createEquipment(NODEID, "uuid2")); + service.writeInventory(createEquipment(NODEID2, "uuid3")); + service.writeInventory(createEquipment(NODEID2, "uuid4")); + service.writeInventory(createEquipment(NODEID2, "uuid5")); + assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal()); + } - private static SearchResult<SearchHit> getDbEntityEntries(Entity entity) { - return dbRawProvider.doReadAllJsonData(entity.getName()); - } + private static SearchResult<SearchHit> getDbEntityEntries(Entity entity) { + return dbRawProvider.doReadAllJsonData(entity.getName()); + } - private static void clearDbEntity(Entity entity) { - DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); - query.setQuery(QueryBuilders.matchAllQuery().toJSON()); - try { - dbRawProvider.deleteByQuery(query); - } catch (IOException e) { - e.printStackTrace(); - } - TestCRUDforDatabase.trySleep(1000); - } + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } - /** - * @param nodeId - * @param uuid - * @return - */ - private Inventory createEquipment(String nodeId, String uuid) { - return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc") - .setManufacturerName("manu").setUuid(uuid).build(); - } + /** + * @param nodeId + * @param uuid + * @return + */ + private Inventory createEquipment(String nodeId, String uuid) { + return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc") + .setManufacturerName("manu").setUuid(uuid).build(); + } - /** - * @param devType - * @param nodename3 - * @return - */ - private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { - return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(1234L) - .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType) - .setIsRequired(true).build(); - } + /** + * @param devType + * @param nodename3 + * @return + */ + private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { + return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(1234L) + .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType) + .setIsRequired(true).build(); + } - /** - * @param nodeId - * @param objectId - * @param problem - * @param severity - * @param counter - * @return - */ - private static FaultlogEntity createFaultLog(String nodeId, String objectId, String problem, SeverityType severity, - int counter) { - return new FaultlogBuilder().setNodeId(nodeId).setObjectId(objectId).setProblem(problem).setSeverity(severity) - .setCounter(counter).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) - .setSourceType(SourceType.Netconf).build(); - } + /** + * @param nodeId + * @param objectId + * @param problem + * @param severity + * @param counter + * @return + */ + private static FaultlogEntity createFaultLog(String nodeId, String objectId, String problem, SeverityType severity, + int counter) { + return new FaultlogBuilder().setNodeId(nodeId).setObjectId(objectId).setProblem(problem).setSeverity(severity) + .setCounter(counter).setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()) + .setSourceType(SourceType.Netconf).build(); + } - /** - * @param nodeId - * @param objectId - * @param attributeName - * @param newValue - * @param counter - * @return - */ - private static EventlogEntity createEventLog(String nodeId, String objectId, String attributeName, String newValue, - int counter) { - return new EventlogBuilder().setNodeId(nodeId).setObjectId(objectId).setAttributeName(attributeName) - .setNewValue(newValue).setCounter(counter) - .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setSourceType(SourceType.Netconf) - .build(); - } + /** + * @param nodeId + * @param objectId + * @param attributeName + * @param newValue + * @param counter + * @return + */ + private static EventlogEntity createEventLog(String nodeId, String objectId, String attributeName, String newValue, + int counter) { + return new EventlogBuilder().setNodeId(nodeId).setObjectId(objectId).setAttributeName(attributeName) + .setNewValue(newValue).setCounter(counter) + .setTimestamp(NetconfTimeStampImpl.getConverter().getTimeStamp()).setSourceType(SourceType.Netconf) + .build(); + } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java index e2009411a..52ca2999d 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestFilterConversion.java @@ -39,36 +39,39 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestFilterConversion { - private static final String PROPERTY = "node-id"; - private static final String PROPERTY2 = "_id"; - private static final String PROPERTY3 = "timestamp"; + private static final String PROPERTY = "node-id"; + private static final String PROPERTY2 = "_id"; + private static final String PROPERTY3 = "timestamp"; - @Test - public void testQuestionMark() { - List<Filter> filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build()); - QueryBuilder query = QueryByFilter.fromFilter(filters); - System.out.println(query.toJSON()); - assertTrue(query.toJSON().contains("{1,1}")); - assertNotNull(QueryByFilter.getFilter(filters, PROPERTY)); - assertNull(QueryByFilter.getFilter(filters, PROPERTY2)); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), - new FilterBuilder().setProperty(PROPERTY2).setFiltervalue("abc").build()); - query = QueryByFilter.fromFilter(filters); - System.out.println(query.toJSON()); - assertNotNull(QueryByFilter.getFilter(filters, PROPERTY2)); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), - new FilterBuilder().setProperty(PROPERTY3).setFiltervalue("<2019-06-13T15:00:12.0Z").build()); - query = QueryByFilter.fromFilter(filters); - List<Sortorder> sortorder = Arrays - .asList(new SortorderBuilder().setProperty(PROPERTY).setSortorder(SortOrder.Ascending).build()); - QueryByFilter.setSortOrder(query, sortorder); - assertNotNull(QueryByFilter.getSortOrder(sortorder, PROPERTY)); - } - @Test - public void testSortorder() { - String f = "{\"input\":{\"filter\":[],\"sortorder\":[{\"property\":\"source-type\",\"sortorder\":\"ascending\"}],\"pagination\":{\"size\":10,\"page\":1}}}"; - - QueryBuilder query = QueryByFilter.setSortOrder(QueryByFilter.fromFilter(null), Arrays.asList(new SortorderBuilder().setProperty("source-type").setSortorder(SortOrder.Ascending).build())); - System.out.println(query.toJSON()); - } + @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()); + assertTrue(query.toJSON().contains("{1,1}")); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY)); + assertNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY2).setFiltervalue("abc").build()); + query = QueryByFilter.fromFilter(filters); + System.out.println(query.toJSON()); + assertNotNull(QueryByFilter.getFilter(filters, PROPERTY2)); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY).setFiltervalue("si?ba").build(), + new FilterBuilder().setProperty(PROPERTY3).setFiltervalue("<2019-06-13T15:00:12.0Z").build()); + query = QueryByFilter.fromFilter(filters); + List<Sortorder> sortorder = + Arrays.asList(new SortorderBuilder().setProperty(PROPERTY).setSortorder(SortOrder.Ascending).build()); + QueryByFilter.setSortOrder(query, sortorder); + assertNotNull(QueryByFilter.getSortOrder(sortorder, PROPERTY)); + } + + @Test + public void testSortorder() { + String f = + "{\"input\":{\"filter\":[],\"sortorder\":[{\"property\":\"source-type\",\"sortorder\":\"ascending\"}],\"pagination\":{\"size\":10,\"page\":1}}}"; + + QueryBuilder query = QueryByFilter.setSortOrder(QueryByFilter.fromFilter(null), Arrays + .asList(new SortorderBuilder().setProperty("source-type").setSortorder(SortOrder.Ascending).build())); + System.out.println(query.toJSON()); + } } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java index 57e1438cc..cc880d1ad 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -44,43 +44,43 @@ import net.bytebuddy.implementation.bytecode.StackSize; */ public class TestImplementation { - @Test - public void test() { - TestConfig.setSDNRDBURLEnv(); - DataProviderImpl impl = new DataProviderImpl(); - impl.setRpcProviderService(new RpcProviderService() { - - @Override - public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, - T implementation, Set<InstanceIdentifier<?>> paths) { - // TODO Auto-generated method stub - return null; - } - - @Override - public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, - T implementation) { - // TODO Auto-generated method stub - return null; - } - }); - impl.setMediatorServerServlet(new MsServlet()); - impl.setAboutServlet(new AboutHttpServlet()); - try { - impl.init(); - } catch (Exception e) { - e.printStackTrace(); - fail("failed to init impl: "+e.getMessage()); - } - - impl.setStatus(StatusKey.CLUSTER_SIZE, "3"); - impl.setReadyStatus(true); - try { - impl.close(); - } catch (Exception e) { - e.printStackTrace(); - fail("failed to close impl: "+e.getMessage()); - } - } - + @Test + public void test() { + TestConfig.setSDNRDBURLEnv(); + DataProviderImpl impl = new DataProviderImpl(); + impl.setRpcProviderService(new RpcProviderService() { + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation, Set<InstanceIdentifier<?>> paths) { + // TODO Auto-generated method stub + return null; + } + + @Override + public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type, + T implementation) { + // TODO Auto-generated method stub + return null; + } + }); + impl.setMediatorServerServlet(new MsServlet()); + impl.setAboutServlet(new AboutHttpServlet()); + try { + impl.init(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to init impl: " + e.getMessage()); + } + + impl.setStatus(StatusKey.CLUSTER_SIZE, "3"); + impl.setReadyStatus(true); + try { + impl.close(); + } catch (Exception e) { + e.printStackTrace(); + fail("failed to close impl: " + e.getMessage()); + } + } + } diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java index 271fe2858..6c22b0ea1 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMaintenanceServiceData.java @@ -49,14 +49,16 @@ public class TestMaintenanceServiceData { private static final String NODEID = "tmsnode1"; private static final String NODEID2 = "tmsnode2"; + @BeforeClass public static void init() throws Exception { dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); - service = dbProvider.getHtDatabaseMaintenance(); + service = dbProvider.getHtDatabaseMaintenance(); } + @Test public void test() throws InterruptedException { clearDbEntity(Entity.Maintenancemode); @@ -67,25 +69,29 @@ public class TestMaintenanceServiceData { obj = service.getMaintenance(NODEID); assertNotNull(obj); List<MaintenanceEntity> list = service.getAll(); - assertEquals("Verify for two ids", 2,list.size()); + assertEquals("Verify for two ids", 2, list.size()); service.deleteIfNotRequired(NODEID); obj = service.getMaintenance(NODEID); assertNull("Check if first id was removed", obj); - obj = service.setMaintenance(createMaintenance(NODEID,true)); + obj = service.setMaintenance(createMaintenance(NODEID, true)); } + /** * @param nodeId * @param active * @return */ private static MaintenanceEntity createMaintenance(String nodeId, Boolean active) { - return new MaintenanceBuilder().setNodeId(nodeId).setActive(active).setProblem("problem").setObjectIdRef("idref").build(); + return new MaintenanceBuilder().setNodeId(nodeId).setActive(active).setProblem("problem") + .setObjectIdRef("idref").build(); } + /** * Delete + * * @param entity */ private static void clearDbEntity(Entity entity) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java index 3192b7f7d..edd0f9edb 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestMediatorServerService.java @@ -45,52 +45,54 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro * */ public class TestMediatorServerService { - private static final String SERVERID = null; - private static ElasticSearchDataProvider dbProvider; - private static HtDatabaseClient dbRawProvider; - private static MediatorServerDataProvider service = null; + private static final String SERVERID = null; + private static ElasticSearchDataProvider dbProvider; + private static HtDatabaseClient dbRawProvider; + private static MediatorServerDataProvider service = null; - - @BeforeClass - public static void init() throws Exception { - dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); - dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); - dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); - service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts); - - - } - @Test - public void test() { - clearDbEntity(Entity.MediatorServer); - System.out.println(service.triggerReloadSync()); - String dbServerId="abc"; - String host = service.getHostUrl(dbServerId); - assertNull(host); - final String NAME="ms1"; - final String HOST = "http://10.20.30.40:7070"; - CreateMediatorServerOutputBuilder output = null; - try { - output = dbProvider.createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build()); - } catch (IOException e) { - e.printStackTrace(); - fail("unable to create ms entry: "+e.getMessage()); - } - System.out.println(service.triggerReloadSync()); - host = service.getHostUrl(output.getId()); - assertEquals(HOST, host); - - } - - private static void clearDbEntity(Entity entity) { - DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); - query.setQuery(QueryBuilders.matchAllQuery().toJSON()); - try { - dbRawProvider.deleteByQuery(query); - } catch (IOException e) { - e.printStackTrace(); - } - TestCRUDforDatabase.trySleep(1000); - } + @BeforeClass + public static void init() throws Exception { + + dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts); + dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS); + dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts); + service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts); + + + } + + @Test + public void test() { + clearDbEntity(Entity.MediatorServer); + System.out.println(service.triggerReloadSync()); + String dbServerId = "abc"; + String host = service.getHostUrl(dbServerId); + assertNull(host); + final String NAME = "ms1"; + final String HOST = "http://10.20.30.40:7070"; + CreateMediatorServerOutputBuilder output = null; + try { + output = dbProvider + .createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build()); + } catch (IOException e) { + e.printStackTrace(); + fail("unable to create ms entry: " + e.getMessage()); + } + System.out.println(service.triggerReloadSync()); + host = service.getHostUrl(output.getId()); + assertEquals(HOST, host); + + } + + private static void clearDbEntity(Entity entity) { + DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName()); + query.setQuery(QueryBuilders.matchAllQuery().toJSON()); + try { + dbRawProvider.deleteByQuery(query); + } catch (IOException e) { + e.printStackTrace(); + } + TestCRUDforDatabase.trySleep(1000); + } } 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 index 83b28a29f..f7a5a841c 100644 --- 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 @@ -44,11 +44,11 @@ public class TestNetconfNodeBuilder { System.out.println(netconfNode); Credentials credentials = netconfNode.getCredentials(); - System.out.println("Class: "+credentials.getClass()+"\nContent: "+credentials); + 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()); + 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 index 104f2272f..1081e3cfe 100644 --- 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 @@ -45,48 +45,51 @@ public class TestNetconfTimestamp { 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(); + private static NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter(); - @Test + @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)); - } + + @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 index a21b01b28..f9c8812a8 100644 --- 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 @@ -38,13 +38,13 @@ public class TestNuMappings { Faultcurrent c = new FaultcurrentBuilder().setSeverity(SeverityType.Critical).build(); YangToolsMapper mapper = new YangToolsMapper(); try { - System.out.println(mapper.writeValueAsString(c)+"<=>"+SeverityType.Critical.getName()); + 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); + Faultcurrent f = mapper.readValue("{\"severity\":\"Critical\"}", Faultcurrent.class); System.out.println(f); System.out.println(mapper.writeValueAsString(f)); } catch (JsonParseException e) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java index a71bfc824..39377d730 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTimestampFilter.java @@ -36,121 +36,138 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro 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"); - } - - @Test - public void testExtra() { - final String PROPERTY_TIMESTAMP = "end"; - List<Filter> filters = null; - QueryBuilder query= null; - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19T*").build()); - query= QueryByFilter.fromFilter(filters ); - assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19*").build()); - query= QueryByFilter.fromFilter(filters ); - assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); - filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020*").build()); - query= QueryByFilter.fromFilter(filters ); - assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-01-01T00:00:00.0Z", "2021-01-01T00:00:00.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"); - } + + @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"); + } + + @Test + public void testExtra() { + final String PROPERTY_TIMESTAMP = "end"; + List<Filter> filters = null; + QueryBuilder query = null; + filters = Arrays + .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19T*").build()); + query = QueryByFilter.fromFilter(filters); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); + filters = Arrays + .asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020-02-19*").build()); + query = QueryByFilter.fromFilter(filters); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-02-19T00:00:00.0Z", "2020-02-20T00:00:00.0Z"); + filters = Arrays.asList(new FilterBuilder().setProperty(PROPERTY_TIMESTAMP).setFiltervalue("2020*").build()); + query = QueryByFilter.fromFilter(filters); + assertRange(query.getInner(), PROPERTY_TIMESTAMP, "2020-01-01T00:00:00.0Z", "2021-01-01T00:00:00.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 index f9267179b..ac97cfe0e 100644 --- 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 @@ -22,7 +22,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; public class TestYangCloning { -/* + /* @Test public void testEquipment() { EquipmentBuilder equipmentBuilder = new EquipmentBuilder(); @@ -35,20 +35,20 @@ public class TestYangCloning { 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:"); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java index 2561a670b..4a0834248 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java @@ -80,9 +80,10 @@ public class TestYangGenSalMapping { loginPasswordBuilder.setPassword("myTestPassword"); netconfNodeBuilder.setCredentials(loginPasswordBuilder.build()); - OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = new OdlHelloMessageCapabilitiesBuilder(); + OdlHelloMessageCapabilitiesBuilder odlHelloMessageCapabilitiesBuilder = + new OdlHelloMessageCapabilitiesBuilder(); List<Uri> uriList = new ArrayList<>(); - uriList.add( new Uri("test.uri") ); + uriList.add(new Uri("test.uri")); odlHelloMessageCapabilitiesBuilder.setCapability(uriList); netconfNodeBuilder.setOdlHelloMessageCapabilities(odlHelloMessageCapabilitiesBuilder.build()); @@ -98,7 +99,7 @@ public class TestYangGenSalMapping { NetconfNode generatedNode = mapper.readValue(res.getBytes(), NetconfNode.class); out(generatedNode.toString()); // Print it with specified indentation // Compare result - out("Equal? "+netconfNode.equals(generatedNode)); + out("Equal? " + netconfNode.equals(generatedNode)); } static class TestDataObjectBuilder implements Builder<TestDataObject> { @@ -118,20 +119,22 @@ public class TestYangGenSalMapping { } @Test - public void test2() throws ClassNotFoundException { + public void test2() throws ClassNotFoundException { - int databasePort = Integer.valueOf(System.getProperty("databaseport")!=null?System.getProperty("databaseport"):"49200"); - System.out.println("DB Port: "+databasePort); + 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)}; + 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); + 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); + 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); @@ -141,7 +144,7 @@ public class TestYangGenSalMapping { } @Test - public void test3() throws IOException { + public void test3() throws IOException { PerformanceDataBuilder performanceBuilder = new PerformanceDataBuilder(); performanceBuilder.setEs(99); @@ -190,59 +193,29 @@ public class TestYangGenSalMapping { @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" + - "}"; + 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); @@ -254,11 +227,12 @@ public class TestYangGenSalMapping { @Test public void test6() throws IOException, ClassNotFoundException { out(method()); - HtDatabaseClient dbClient = new HtDatabaseClient(new HostInfo[] { new HostInfo("sdnrdb", 9200, Protocol.HTTP) }); + 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); + 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(); @@ -277,12 +251,13 @@ public class TestYangGenSalMapping { 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); + 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; + out("Found: " + result.getHits().size()); + int t = 0; for (Data hit : result.getHits()) { - out("Hit "+t+++":"+hit); + out("Hit " + t++ + ":" + hit); } setPagination(outputBuilder, page, pageSize, result.getTotal()); outputBuilder.setData(result.getHits()); @@ -292,19 +267,20 @@ public class TestYangGenSalMapping { 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) }); + 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"); + .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"); + String id = mediatorserverRW.write(inputBuilder.build(), "testid"); System.out.println(id); } @@ -314,15 +290,15 @@ public class TestYangGenSalMapping { out(method()); String input; input = "id-dd-dd"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "idDdGg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "_idDdGg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = "--ff--gfg"; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); input = ""; - System.out.println("Map " + input + " to "+YangToolsMapper.toCamelCaseAttributeName(input)); + System.out.println("Map " + input + " to " + YangToolsMapper.toCamelCaseAttributeName(input)); } /* --------------------------------- @@ -333,7 +309,8 @@ public class TestYangGenSalMapping { 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) { + 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); @@ -371,10 +348,9 @@ public class TestYangGenSalMapping { if (filters == null || filters.size() == 0) { return QueryBuilders.matchAllQuery(); - } else if(filters.size()==1){ + } else if (filters.size() == 1) { return QueryBuilders.matchQuery(filters.get(0).getProperty(), filters.get(0).getFiltervalue()); - } - else { + } else { BoolQueryBuilder query = new BoolQueryBuilder(); for (Filter fi : filters) { query.must(QueryBuilders.matchQuery((prefix != null ? prefix : "") + fi.getProperty(), @@ -384,6 +360,7 @@ public class TestYangGenSalMapping { } } + private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder) { return setSortOrder(query, sortorder, ""); } @@ -401,9 +378,12 @@ public class TestYangGenSalMapping { } - 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(); + 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 index 7341d5a33..19bd76cae 100644 --- 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 @@ -55,145 +55,150 @@ 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); - } - } + 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); + } + } } |