Search in sources :

Example 31 with CacheXmlException

use of org.apache.geode.cache.CacheXmlException in project geode by apache.

the class DiskRegionIllegalCacheXMLvaluesJUnitTest method createRegion.

public void createRegion(String path) {
    DistributedSystem ds = null;
    try {
        boolean exceptionOccurred = false;
        File dir = new File("testingDirectoryForXML");
        dir.mkdir();
        dir.deleteOnExit();
        Properties props = new Properties();
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(CACHE_XML_FILE, TestUtil.getResourcePath(getClass(), path));
        ds = DistributedSystem.connect(props);
        try {
            CacheFactory.create(ds);
        } catch (IllegalArgumentException ex) {
            exceptionOccurred = true;
            System.out.println("ExpectedStrings: Received expected IllegalArgumentException:" + ex.getMessage());
        } catch (CacheXmlException ex) {
            exceptionOccurred = true;
            System.out.println("ExpectedStrings: Received expected CacheXmlException:" + ex.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            fail("test failed due to " + e);
        }
        if (!exceptionOccurred) {
            fail(" exception did not occur although was expected");
        }
    } finally {
        if (ds != null && ds.isConnected()) {
            ds.disconnect();
            ds = null;
        }
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) File(java.io.File) CacheXmlException(org.apache.geode.cache.CacheXmlException)

Example 32 with CacheXmlException

use of org.apache.geode.cache.CacheXmlException in project geode by apache.

the class LuceneXmlParser method startIndex.

private void startIndex(Attributes atts) {
    if (!(stack.peek() instanceof RegionCreation)) {
        throw new CacheXmlException("lucene <index> elements must occur within <region> elements");
    }
    final RegionCreation region = (RegionCreation) stack.peek();
    String name = atts.getValue(NAME);
    LuceneIndexCreation indexCreation = new LuceneIndexCreation();
    indexCreation.setName(name);
    indexCreation.setRegion(region);
    region.getExtensionPoint().addExtension(indexCreation);
    stack.push(indexCreation);
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation)

Example 33 with CacheXmlException

use of org.apache.geode.cache.CacheXmlException in project geode by apache.

the class CacheXml66DUnitTest method testMalformed.

/**
   * Tests parsing a malformed XML file
   */
@Test
public void testMalformed() throws Exception {
    setXmlFile(findFile("malformed.xml"));
    IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
    try {
        getCache();
        fail("Should have thrown a CacheXmlException");
    } catch (CacheXmlException ex) {
        assertTrue(ex.getCause() instanceof SAXException);
    } finally {
        expectedException.remove();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 34 with CacheXmlException

use of org.apache.geode.cache.CacheXmlException in project geode by apache.

the class CacheXml81DUnitTest method testLocatorInException.

/**
   * Test {@link Locator} is used in {@link SAXParseException}. Exercises
   * {@link XmlParser#setDocumentLocator(Locator)}
   * 
   * @since GemFire 8.2
   */
@Test
public void testLocatorInException() throws Exception {
    final String regionName = "testRegionExtension";
    final CacheCreation cache = new CacheCreation();
    final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    @SuppressWarnings("unchecked") Extensible<Region<?, ?>> region = (Extensible<Region<?, ?>>) cache.createRegion(regionName, attrs);
    final MockRegionExtension extension = new MockRegionExtension("exception");
    region.getExtensionPoint().addExtension(extension);
    assertEquals(0, extension.beforeCreateCounter.get());
    assertEquals(0, extension.onCreateCounter.get());
    assertEquals(0, extension.getXmlGeneratorCounter.get());
    IgnoredException.addIgnoredException("While reading Cache XML file");
    try {
        testXml(cache);
        fail("Excepted CacheXmlException");
    } catch (final CacheXmlException e) {
        if (e.getCause() instanceof SAXParseException) {
            assertTrue(((SAXParseException) e.getCause()).getLineNumber() > 0);
            assertTrue(((SAXParseException) e.getCause()).getColumnNumber() > 0);
            assertEquals("Value is 'exception'.", e.getCause().getMessage());
        }
    }
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) CacheXmlException(org.apache.geode.cache.CacheXmlException) SAXParseException(org.xml.sax.SAXParseException) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) Region(org.apache.geode.cache.Region) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) MockRegionExtension(org.apache.geode.internal.cache.extension.mock.MockRegionExtension) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 35 with CacheXmlException

use of org.apache.geode.cache.CacheXmlException in project geode by apache.

the class CacheXml66DUnitTest method testBadFloat.

/**
   * Tests parsing an XML file with a bad float
   */
@Test
public void testBadFloat() throws Exception {
    setXmlFile(findFile("badFloat.xml"));
    IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
    try {
        getCache();
        fail("Should have thrown a CacheXmlException");
    } catch (CacheXmlException ex) {
        assertTrue(ex.getCause() instanceof NumberFormatException);
    } finally {
        expectedException.remove();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test)

Aggregations

CacheXmlException (org.apache.geode.cache.CacheXmlException)51 Declarable (org.apache.geode.cache.Declarable)22 SAXException (org.xml.sax.SAXException)13 Test (org.junit.Test)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)11 IOException (java.io.IOException)10 RegionExistsException (org.apache.geode.cache.RegionExistsException)9 CacheException (org.apache.geode.cache.CacheException)8 SAXParseException (org.xml.sax.SAXParseException)8 File (java.io.File)7 EmptyStackException (java.util.EmptyStackException)7 InternalGemFireException (org.apache.geode.InternalGemFireException)7 CacheWriterException (org.apache.geode.cache.CacheWriterException)7 GatewayException (org.apache.geode.cache.GatewayException)7 TimeoutException (org.apache.geode.cache.TimeoutException)7 Properties (java.util.Properties)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2