From 98966ee8eac5cec1c1680e59db43bf4aa84fcac5 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 20 Jul 2024 15:55:19 +0200 Subject: [PATCH] Refactored HttpErrorLogs tests. --- .../httperror/HttpErrorLogIteratorTest.java | 100 ++++++++++++++++++ ...st.java => HttpErrorLogsAnalyzerTest.java} | 54 +--------- 2 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogIteratorTest.java rename test/fr/devinsy/statoolinfos/metrics/httperror/{HttpErrorLogsTest.java => HttpErrorLogsAnalyzerTest.java} (82%) diff --git a/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogIteratorTest.java b/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogIteratorTest.java new file mode 100644 index 0000000..2125071 --- /dev/null +++ b/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogIteratorTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2021-2024 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple key value database. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.metrics.httperror; + +import java.io.File; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLog; +import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLogIterator; +import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLogs; +import fr.devinsy.statoolinfos.util.Files; +import fr.devinsy.statoolinfos.util.FilesUtils; + +/** + * The Class HttpErrorLogsTest. + */ +public class HttpErrorLogIteratorTest +{ + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HttpErrorLogIteratorTest.class); + + /** + * Test 01. + * + * @throws Exception + * the exception + */ + @Test + public void test01() throws Exception + { + System.out.println(System.getProperty("user.dir")); + + String source = "./test/fr/devinsy/statoolinfos/metrics/httperror/data/paste.libre-service.eu/paste*"; + Files files = FilesUtils.searchByWildcard(source); + for (File file : files) + { + System.out.println(file); + } + HttpErrorLogs logs = new HttpErrorLogs(files); + HttpErrorLogIterator iterator = (HttpErrorLogIterator) logs.iterator(); + while (iterator.hasNext()) + { + HttpErrorLog log = iterator.next(); + System.out.println(log.toStringLog()); + } + + // System.out.println(iterator.getLogCount()); + // System.out.println(iterator.getFailedLogCount()); + + Assert.assertEquals(315, iterator.getLogCount()); + Assert.assertEquals(0, iterator.getFailedLogCount()); + } + + /** + * After class. + * + * @throws StatoolInfosException + * the Juga exception + */ + @AfterClass + public static void afterClass() throws StatoolInfosException + { + } + + /** + * Before class. + * + * @throws StatoolInfosException + * the Juga exception + */ + @BeforeClass + public static void beforeClass() throws StatoolInfosException + { + Configurator.initialize(new DefaultConfiguration()); + Configurator.setRootLevel(Level.DEBUG); + } +} diff --git a/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsTest.java b/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsAnalyzerTest.java similarity index 82% rename from test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsTest.java rename to test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsAnalyzerTest.java index dca1527..04c16df 100644 --- a/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsTest.java +++ b/test/fr/devinsy/statoolinfos/metrics/httperror/HttpErrorLogsAnalyzerTest.java @@ -32,9 +32,7 @@ import fr.devinsy.statoolinfos.core.Configuration; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.metrics.PathCounters; import fr.devinsy.statoolinfos.metrics.Prober; -import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLog; import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLogAnalyzer; -import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLogIterator; import fr.devinsy.statoolinfos.metrics.httperrorlog.HttpErrorLogs; import fr.devinsy.statoolinfos.util.Files; import fr.devinsy.statoolinfos.util.FilesUtils; @@ -42,53 +40,15 @@ import fr.devinsy.statoolinfos.util.FilesUtils; /** * The Class HttpErrorLogsTest. */ -public class HttpErrorLogsTest +public class HttpErrorLogsAnalyzerTest { - private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HttpErrorLogsTest.class); + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HttpErrorLogsAnalyzerTest.class); - /** - * Test 01. - * - * @throws Exception - * the exception - */ @Test public void test01() throws Exception { System.out.println(System.getProperty("user.dir")); - String source = "./test/fr/devinsy/statoolinfos/metrics/httperror/data/paste.libre-service.eu/paste*"; - Files files = FilesUtils.searchByWildcard(source); - for (File file : files) - { - System.out.println(file); - } - HttpErrorLogs logs = new HttpErrorLogs(files); - HttpErrorLogIterator iterator = (HttpErrorLogIterator) logs.iterator(); - while (iterator.hasNext()) - { - HttpErrorLog log = iterator.next(); - System.out.println(log.toStringLog()); - } - - // System.out.println(iterator.getLogCount()); - // System.out.println(iterator.getFailedLogCount()); - - Assert.assertEquals(315, iterator.getLogCount()); - Assert.assertEquals(0, iterator.getFailedLogCount()); - } - - /** - * Test 02. - * - * @throws Exception - * the exception - */ - @Test - public void test02() throws Exception - { - System.out.println(System.getProperty("user.dir")); - String source = "./test/fr/devinsy/statoolinfos/metrics/httperror/data/paste.libre-service.eu/paste*"; Files files = FilesUtils.searchByWildcard(source); for (File file : files) @@ -112,14 +72,8 @@ public class HttpErrorLogsTest Assert.assertEquals(25, counters.getCount("metrics.http.errors", "2023-08")); } - /** - * Test 03. - * - * @throws Exception - * the exception - */ @Test - public void test03() throws Exception + public void test02() throws Exception { System.out.println(System.getProperty("user.dir")); @@ -163,7 +117,7 @@ public class HttpErrorLogsTest } @Test - public void test04() throws Exception + public void test03() throws Exception { System.out.println(System.getProperty("user.dir"));