PageRenderTime 29ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/com.plugin.log4j.viewer/tests/com/log4jviewer/filters/ConfigFilterSaverTest.java

https://code.google.com/p/log4j-viewer/
Java | 100 lines | 76 code | 19 blank | 5 comment | 16 complexity | 6e08c8695743cd14a97df27b36e2647e MD5 | raw file
  1. package com.log4jviewer.filters;
  2. import java.util.List;
  3. import junit.framework.Assert;
  4. import org.junit.Test;
  5. /**
  6. * Test class for checking the storing of XML config file
  7. *
  8. * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
  9. */
  10. public class ConfigFilterSaverTest {
  11. private static final String LOADER_FILE_PATH = "testinputs/log4jviewer/filters/ConfigLoaderTestInput.xml";
  12. private static final String SAVER_FILE_PATH = "testinputs/log4jviewer/filters/ConfigSaverTestInput.xml";
  13. @Test
  14. public void testSaver() throws Exception {
  15. ConfigFilterLoader cl = new ConfigFilterLoader();
  16. List<FilterModel> filterModels = cl.loadFilters(LOADER_FILE_PATH);
  17. filterModels.add(new FilterModel());
  18. int filtrSize = filterModels.size();
  19. filterModels.get(filtrSize - 1).setFilterName("Filter3");
  20. filterModels.get(filtrSize - 1).setFilterDescr("Show all logs with throwable 'Exception error!!'");
  21. FilterItemModel items = new FilterItemModel();
  22. items.setLogicOperand(FilterItemModel.LogicOperand.OR);
  23. items.setFieldType(FilterItemModel.FieldType.THROWABLE);
  24. items.setInclude(true);
  25. items.setPattern("Exception error!!");
  26. items.setEnabled(true);
  27. filterModels.get(filtrSize - 1).addItem(items);
  28. ConfigFilterSaver cs = new ConfigFilterSaver();
  29. cs.saveFilters(SAVER_FILE_PATH, filterModels);
  30. filterModels = cl.loadFilters(SAVER_FILE_PATH);
  31. for (int i = 0; i < filterModels.size(); i++) {
  32. for (int j = 0; j < filterModels.get(i).getItemsCount(); j++) {
  33. if (i == 0) {
  34. Assert.assertEquals("Filter1", filterModels.get(i).getFilterName());
  35. Assert.assertEquals("Show all logs with level DEBUG, or hide all messages with 'select * from'",
  36. filterModels.get(i).getFilterDescr());
  37. if (j == 0) {
  38. Assert.assertEquals("and", filterModels.get(i).getItem(j).getLogicOperand().getValue());
  39. Assert.assertEquals("level", filterModels.get(i).getItem(j).getFieldType().getValue());
  40. Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
  41. Assert.assertEquals("debug", filterModels.get(i).getItem(j).getPattern());
  42. Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
  43. }
  44. if (j == 1) {
  45. Assert.assertEquals("or", filterModels.get(i).getItem(j).getLogicOperand().getValue());
  46. Assert.assertEquals("message", filterModels.get(i).getItem(j).getFieldType().getValue());
  47. Assert.assertEquals(false, filterModels.get(i).getItem(j).isInclude());
  48. Assert.assertEquals("select * from", filterModels.get(i).getItem(j)
  49. .getPattern());
  50. Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
  51. }
  52. }
  53. if (i == 1) {
  54. Assert.assertEquals("Filter2", filterModels.get(i).getFilterName());
  55. Assert.assertEquals("Show line# 7", filterModels.get(i).getFilterDescr());
  56. if (j == 0) {
  57. Assert.assertEquals("and", filterModels.get(i).getItem(j).getLogicOperand().getValue());
  58. Assert.assertEquals("line", filterModels.get(i).getItem(j).getFieldType().getValue());
  59. Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
  60. Assert.assertEquals("7", filterModels.get(i).getItem(j).getPattern());
  61. Assert.assertEquals(false, filterModels.get(i).getItem(j).isEnabled());
  62. }
  63. }
  64. if (i == 2) {
  65. Assert.assertEquals("Filter3", filterModels.get(i).getFilterName());
  66. Assert.assertEquals("Show all logs with throwable 'Exception error!!'", filterModels.get(i)
  67. .getFilterDescr());
  68. if (j == 0) {
  69. Assert.assertEquals("or", filterModels.get(i).getItem(j).getLogicOperand().getValue());
  70. Assert.assertEquals("throwable", filterModels.get(i).getItem(j).getFieldType().getValue());
  71. Assert.assertEquals(true, filterModels.get(i).getItem(j).isInclude());
  72. Assert.assertEquals("Exception error!!", filterModels.get(i).getItem(j)
  73. .getPattern());
  74. Assert.assertEquals(true, filterModels.get(i).getItem(j).isEnabled());
  75. }
  76. }
  77. }
  78. }
  79. Assert.assertEquals(3, filterModels.size());
  80. }
  81. }