/com.plugin.log4j.viewer/tests/com/log4jviewer/filters/ConfigFilterSaverTest.java
Java | 100 lines | 76 code | 19 blank | 5 comment | 16 complexity | 6e08c8695743cd14a97df27b36e2647e MD5 | raw file
- package com.log4jviewer.filters;
- import java.util.List;
- import junit.framework.Assert;
- import org.junit.Test;
- /**
- * Test class for checking the storing of XML config file
- *
- * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
- */
- public class ConfigFilterSaverTest {
- private static final String LOADER_FILE_PATH = "testinputs/log4jviewer/filters/ConfigLoaderTestInput.xml";
- private static final String SAVER_FILE_PATH = "testinputs/log4jviewer/filters/ConfigSaverTestInput.xml";
- @Test
- public void testSaver() throws Exception {
- ConfigFilterLoader cl = new ConfigFilterLoader();
- List<FilterModel> filterModels = cl.loadFilters(LOADER_FILE_PATH);
- filterModels.add(new FilterModel());
- int filtrSize = filterModels.size();
- filterModels.get(filtrSize - 1).setFilterName("Filter3");
- filterModels.get(filtrSize - 1).setFilterDescr("Show all logs with throwable 'Exception error!!'");
- FilterItemModel items = new FilterItemModel();
- items.setLogicOperand(FilterItemModel.LogicOperand.OR);
- items.setFieldType(FilterItemModel.FieldType.THROWABLE);
- items.setInclude(true);
- items.setPattern("Exception error!!");
- items.setEnabled(true);
- filterModels.get(filtrSize - 1).addItem(items);
- ConfigFilterSaver cs = new ConfigFilterSaver();
- cs.saveFilters(SAVER_FILE_PATH, filterModels);
- filterModels = cl.loadFilters(SAVER_FILE_PATH);
- for (int i = 0; i < filterModels.size(); i++) {
- for (int j = 0; j < filterModels.get(i).getItemsCount(); j++) {
- if (i == 0) {
- Assert.assertEquals("Filter1", filterModels.get(i).getFilterName());
- Assert.assertEquals("Show all logs with level DEBUG, or hide all messages with 'select * from'",
- filterModels.get(i).getFilterDescr());
- if (j == 0) {
- Assert.assertEquals("and", filterModels.get(i).getItem(j).getLogicOperand().getValue());
- Assert.assertEquals("level", filterModels.get(i).getItem(j).getFieldType().getValue());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
- Assert.assertEquals("debug", filterModels.get(i).getItem(j).getPattern());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
- }
- if (j == 1) {
- Assert.assertEquals("or", filterModels.get(i).getItem(j).getLogicOperand().getValue());
- Assert.assertEquals("message", filterModels.get(i).getItem(j).getFieldType().getValue());
- Assert.assertEquals(false, filterModels.get(i).getItem(j).isInclude());
- Assert.assertEquals("select * from", filterModels.get(i).getItem(j)
- .getPattern());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
- }
- }
- if (i == 1) {
- Assert.assertEquals("Filter2", filterModels.get(i).getFilterName());
- Assert.assertEquals("Show line# 7", filterModels.get(i).getFilterDescr());
- if (j == 0) {
- Assert.assertEquals("and", filterModels.get(i).getItem(j).getLogicOperand().getValue());
- Assert.assertEquals("line", filterModels.get(i).getItem(j).getFieldType().getValue());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
- Assert.assertEquals("7", filterModels.get(i).getItem(j).getPattern());
- Assert.assertEquals(false, filterModels.get(i).getItem(j).isEnabled());
- }
- }
- if (i == 2) {
- Assert.assertEquals("Filter3", filterModels.get(i).getFilterName());
- Assert.assertEquals("Show all logs with throwable 'Exception error!!'", filterModels.get(i)
- .getFilterDescr());
- if (j == 0) {
- Assert.assertEquals("or", filterModels.get(i).getItem(j).getLogicOperand().getValue());
- Assert.assertEquals("throwable", filterModels.get(i).getItem(j).getFieldType().getValue());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
- Assert.assertEquals("Exception error!!", filterModels.get(i).getItem(j)
- .getPattern());
- Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
- }
- }
- }
- }
- Assert.assertEquals(3, filterModels.size());
- }
- }