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;
}
}
}
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);
}
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();
}
}
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());
}
}
}
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();
}
}
Aggregations