Search in sources :

Example 1 with ParserTypes

use of alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes in project ACS by ACS-Community.

the class ConvertersTest method setUp.

/**
	 * @see junit.framework.TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    ParserTypes type = ParserTypes.VTD;
    ACSLogParser parser = ACSLogParserFactory.getParser(type);
    logToConvert = parser.parse(xmlLog);
}
Also used : ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser)

Example 2 with ParserTypes

use of alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes in project ACS by ACS-Community.

the class ACSLogParserTest method testMultipleParse.

/**
	 * Call the parser several times
	 * 
	 * @throws Exception
	 */
public void testMultipleParse() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testMultipleParse: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        String[] logs = new String[3 * 1000];
        for (int t = 0; t < logs.length; t += 3) {
            logs[t] = xmlLogInfo1;
            logs[t + 1] = xmlLogInfo2;
            logs[t + 2] = xmlLogWarningWithException;
        }
        for (String xmlLog : logs) {
            ILogEntry log = parser.parse(xmlLog);
            assertNotNull(log);
        }
    }
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)

Example 3 with ParserTypes

use of alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes in project ACS by ACS-Community.

the class ACSLogParserTest method testParseLogRecord.

/**
	 * Parses one log record from XML and verifies a few fields, 
	 * including the exception details that are attached as additional data.
	 * 
	 * @throws Exception
	 */
public void testParseLogRecord() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testParseLogRecord: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        ILogEntry log = parser.parse(xmlLogWarningWithException);
        // verify some fields
        assertEquals("wrong typename string", "Warning", ((LogTypeHelper) log.getField(LogField.ENTRYTYPE)).logEntryType);
        assertEquals("wrong type code", LogTypeHelper.WARNING, ((LogTypeHelper) log.getField(LogField.ENTRYTYPE)));
        Vector<ILogEntry.AdditionalData> additionalData = log.getAdditionalData();
        assertFalse("There should have been 2 pieces of additional data!", additionalData == null || additionalData.size() != 2);
        // Check the first data
        ILogEntry.AdditionalData myData = additionalData.get(0);
        assertEquals("LoggedException", myData.name);
        assertTrue(myData.value.startsWith("alma.xmlstore.OperationalPackage.NotFound: uid://X00000000000028aa/X00000002"));
        // Check the second data
        ILogEntry.AdditionalData d = additionalData.get(1);
        assertEquals("Pippo", d.name);
        assertEquals("Pluto", d.value);
    }
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes) AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData)

Example 4 with ParserTypes

use of alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes in project ACS by ACS-Community.

the class ConvertersTest method testXML.

/**
	 * Test the XML conversion
	 * 
	 * @throws Exception
	 */
public void testXML() throws Exception {
    XMLConverter converter = new XMLConverter();
    assertNotNull(converter);
    String ret = converter.convert(logToConvert);
    assertNotNull(ret);
    ParserTypes type = ParserTypes.VTD;
    ACSLogParser parser = ACSLogParserFactory.getParser(type);
    ILogEntry log = parser.parse(ret);
    assertNotNull(log);
    for (LogField f : LogField.values()) {
        Object original = logToConvert.getField(f);
        Object converted = log.getField(f);
        assertEquals(original, converted);
    }
    Vector<AdditionalData> originalData = logToConvert.getAdditionalData();
    assertNotNull(originalData);
    Vector<AdditionalData> convertedData = log.getAdditionalData();
    assertNotNull(convertedData);
    assertEquals(originalData.size(), convertedData.size());
    for (AdditionalData ad : originalData) {
        boolean found = false;
        String name = ad.name;
        String val = ad.value;
        for (AdditionalData adConverted : convertedData) {
            if (name.equals(adConverted.name)) {
                found = true;
                assertEquals(val, adConverted.value);
                break;
            }
        }
        assertTrue("Additional data not found", found);
    }
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) XMLConverter(alma.acs.logging.tools.XMLConverter) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes) ACSLogParser(alma.acs.logging.engine.parser.ACSLogParser) LogField(com.cosylab.logging.engine.log.LogField)

Example 5 with ParserTypes

use of alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes in project ACS by ACS-Community.

the class ACSLogParserTest method testSpecialLogs.

/**
	 * Test special logs i.e. logs that sometime have returned errors while parsing.
	 * 
	 * @see <code>specialLogs</code>
	 * @throws Exception
	 */
public void testSpecialLogs() throws Exception {
    // Cycle through all available parsers
    for (ParserTypes type : ParserTypes.values()) {
        System.out.println("testSpecialLogs: Testing parser " + type);
        parser = ACSLogParserFactory.getParser(type);
        assertNotNull(parser);
        assertEquals(type, ACSLogParserFactory.getParserType(parser));
        for (String xmlLog : specialLogs) {
            ILogEntry log = parser.parse(xmlLog);
            Vector<AdditionalData> data = log.getAdditionalData();
            if (data != null) {
                for (int t = 0; t < data.size(); t++) {
                    AdditionalData d = data.get(t);
                    System.out.println("Data:  name=" + d.name + ", value=" + d.value);
                }
            } else {
                System.out.println("The log has no additional data entries");
            }
            System.out.println("Body: " + log.getField(LogField.LOGMESSAGE));
        }
    }
}
Also used : AdditionalData(com.cosylab.logging.engine.log.ILogEntry.AdditionalData) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ParserTypes(alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)

Aggregations

ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)6 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)5 AdditionalData (com.cosylab.logging.engine.log.ILogEntry.AdditionalData)3 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)2 XMLConverter (alma.acs.logging.tools.XMLConverter)1 IsoDateFormat (alma.acs.util.IsoDateFormat)1 LogField (com.cosylab.logging.engine.log.LogField)1 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1