Search in sources :

Example 1 with ReaderExtractor

use of alma.acs.util.ReaderExtractor in project ACS by ACS-Community.

the class LogConfigTest method testGetLogConfigXml.

/**
	 * Test for the XPath based {@link LogConfig#getLogConfigXml(String, String)} which extracts log info from the XML 
	 * that we get from the CDB.
	 */
public void testGetLogConfigXml() throws Exception {
    logger.info("============ Running testGetLogConfigXml ============");
    File containerConfigFile = new File("frodoContainer.xml");
    assertTrue("Cannot find file frodoContainer.xml. Check that file exists and test is run with working dir acsjlog/test.", containerConfigFile.exists());
    String containerConfigXml = (new ReaderExtractor((new FileReader(containerConfigFile)))).extract();
    logger.info("containerConfigXml = " + containerConfigXml);
    assertNotNull(containerConfigXml);
    assertFalse(containerConfigXml.isEmpty());
    TestCDB testCDB = new TestCDB();
    logConfig.setCDB(testCDB);
    String cdbContainerConfigPath = "frodoContainer";
    testCDB.addCurlToXmlMapping(cdbContainerConfigPath, containerConfigXml);
    logConfig.setCDBLoggingConfigPath(cdbContainerConfigPath);
    String xml = logConfig.getLogConfigXml(cdbContainerConfigPath, "//" + LogConfig.CDBNAME_LoggingConfig);
    assertNotNull(xml);
    logger.info("Got container logging config xml: " + xml);
    LoggingConfig loggingConfig = LoggingConfig.unmarshalLoggingConfig(new StringReader(xml));
    assertNotNull(loggingConfig);
    String separateConfigComponent1 = "testComp1";
    String separateConfigComponent2 = "testComp2";
    String componentsXml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " + "<Components xmlns=\"urn:schemas-cosylab-com:Components:1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> " + createComponentsCdbXml(separateConfigComponent1, "IDL_TYPE_1", "some.class1", "zampaione", true, 2, 8) + createComponentsCdbXml(separateConfigComponent2, "IDL_TYPE_2", "some.class2", "zampaione", true, 5, 6) + "</Components>";
    logger.info("componentsXml = " + componentsXml);
    String cdbComponentsPath = "MACI/Components";
    logConfig.setCDB(testCDB);
    testCDB.addCurlToXmlMapping(cdbComponentsPath, componentsXml);
    logConfig.setCDBComponentPath(separateConfigComponent1, cdbComponentsPath);
    logConfig.setCDBComponentPath(separateConfigComponent2, cdbComponentsPath);
    String expr = "//_[@Name='" + separateConfigComponent2 + "']/ComponentLogger";
    xml = logConfig.getLogConfigXml("MACI/Components", expr);
    assertNotNull(xml);
    logger.info("Got component config xml: " + xml);
    UnnamedLogger compLoggerConfig = UnnamedLogger.unmarshalUnnamedLogger(new StringReader(xml));
    assertNotNull(compLoggerConfig);
}
Also used : ReaderExtractor(alma.acs.util.ReaderExtractor) UnnamedLogger(alma.maci.loggingconfig.UnnamedLogger) LoggingConfig(alma.maci.loggingconfig.LoggingConfig) StringReader(java.io.StringReader) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

ReaderExtractor (alma.acs.util.ReaderExtractor)1 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)1 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)1 File (java.io.File)1 FileReader (java.io.FileReader)1 StringReader (java.io.StringReader)1