diff --git a/src/main/java/org/mongeez/reader/FilesetXMLReader.java b/src/main/java/org/mongeez/reader/FilesetXMLReader.java index 7089509..7bbc92e 100644 --- a/src/main/java/org/mongeez/reader/FilesetXMLReader.java +++ b/src/main/java/org/mongeez/reader/FilesetXMLReader.java @@ -42,11 +42,17 @@ public List getFiles(Resource file) { digester.addSetNext("changeFiles/file", "add"); ChangeFileSet changeFileSet = (ChangeFileSet) digester.parse(file.getInputStream()); - logger.info("Num of changefiles " + changeFileSet.getChangeFiles().size()); - - for (ChangeFile changeFile : changeFileSet.getChangeFiles()) { - files.add(file.createRelative(changeFile.getPath())); - } + if (changeFileSet != null) { + logger.info("Num of changefiles " + changeFileSet.getChangeFiles().size()); + + for (ChangeFile changeFile : changeFileSet.getChangeFiles()) { + files.add(file.createRelative(changeFile.getPath())); + } + } + else { + logger.error("The file {} doesn't seem to contain a changeFiles declaration. Are you " + + "using the correct file to initialize Mongeez?", file.getFilename()); + } } catch (IOException e) { logger.error("IOException", e); } catch (org.xml.sax.SAXException e) { diff --git a/src/main/java/org/mongeez/reader/XmlChangeSetReader.java b/src/main/java/org/mongeez/reader/XmlChangeSetReader.java index 048b5dd..10b3b12 100644 --- a/src/main/java/org/mongeez/reader/XmlChangeSetReader.java +++ b/src/main/java/org/mongeez/reader/XmlChangeSetReader.java @@ -56,10 +56,15 @@ public List getChangeSets(Resource file) { try { ChangeSetList changeFileSet = (ChangeSetList) digester.parse(file.getInputStream()); - for (ChangeSet changeSet : changeFileSet.getList()) { - ChangeSetReaderUtil.populateChangeSetResourceInfo(changeSet, file); - } - changeSets.addAll(changeFileSet.getList()); + if (changeFileSet.getList() == null) { + logger.warn("Ignoring change file {}, it does not contain any changeSets", file.getFilename()); + } + else { + for (ChangeSet changeSet : changeFileSet.getList()) { + ChangeSetReaderUtil.populateChangeSetResourceInfo(changeSet, file); + } + changeSets.addAll(changeFileSet.getList()); + } } catch (IOException e) { logger.error("IOException", e); } catch (org.xml.sax.SAXException e) { diff --git a/src/test/java/org/mongeez/MongeezTest.java b/src/test/java/org/mongeez/MongeezTest.java index c5f73ae..06a4d39 100644 --- a/src/test/java/org/mongeez/MongeezTest.java +++ b/src/test/java/org/mongeez/MongeezTest.java @@ -84,4 +84,23 @@ public void testNoFiles() throws Exception { assertEquals(db.getCollection("mongeez").count(), 1); } + + @Test(groups = "dao") + public void testNoFailureOnEmptyChangeLog() throws Exception { + assertEquals(db.getCollection("mongeez").count(), 0); + + Mongeez mongeez = create("mongeez_empty_changelog.xml"); + mongeez.process(); + + assertEquals(db.getCollection("mongeez").count(), 1); + } + + @Test(groups = "dao") + public void testNoFailureOnNoChangeFilesBlock() throws Exception { + assertEquals(db.getCollection("mongeez").count(), 0); + + Mongeez mongeez = create("mongeez_no_changefiles_declared.xml"); + mongeez.process(); + assertEquals(db.getCollection("mongeez").count(), 1); + } } diff --git a/src/test/resources/empty_changeset.xml b/src/test/resources/empty_changeset.xml new file mode 100644 index 0000000..5b07d53 --- /dev/null +++ b/src/test/resources/empty_changeset.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/test/resources/mongeez_empty_changelog.xml b/src/test/resources/mongeez_empty_changelog.xml new file mode 100644 index 0000000..b339773 --- /dev/null +++ b/src/test/resources/mongeez_empty_changelog.xml @@ -0,0 +1,6 @@ + + + + diff --git a/src/test/resources/mongeez_no_changefiles_declared.xml b/src/test/resources/mongeez_no_changefiles_declared.xml new file mode 100644 index 0000000..1a6cca0 --- /dev/null +++ b/src/test/resources/mongeez_no_changefiles_declared.xml @@ -0,0 +1,5 @@ + + +