NIHVIVO-3628 convert PropertyListConfig and InvalidConfigurationException from inner classes on ObjectPropertyTemplateModel to top-level classes. Combine InvalidConfigurationException with InvalidConfigFileException. Adjust tests accordingly.

This commit is contained in:
j2blake 2012-02-22 21:40:48 +00:00
parent 6a4228f099
commit 11d32685cf
8 changed files with 313 additions and 269 deletions

View file

@ -17,8 +17,6 @@ import org.junit.matchers.JUnitMatchers;
import org.junit.rules.ExpectedException;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.CustomListViewConfigFile;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.CustomListViewConfigFile.InvalidConfigFileException;
/**
* Note: when testing, an "empty" element may be self-closing, or with
@ -59,19 +57,19 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
// ----------------------------------------------------------------------
@Test
public void readerIsNull() throws InvalidConfigFileException {
public void readerIsNull() throws InvalidConfigurationException {
expectException("Config file reader is null.");
configFile = new CustomListViewConfigFile(null);
}
@Test
public void readerThrowsIOException() throws InvalidConfigFileException {
public void readerThrowsIOException() throws InvalidConfigurationException {
expectException("Unable to read config file.");
configFile = new CustomListViewConfigFile(new ExplodingReader());
}
@Test
public void invalidXml() throws InvalidConfigFileException {
public void invalidXml() throws InvalidConfigurationException {
suppressSyserr(); // catch the error report from the XML parser
expectException(JUnitMatchers
.containsString("Config file is not valid XML:"));
@ -79,14 +77,14 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void selectQueryMissing() throws InvalidConfigFileException {
public void selectQueryMissing() throws InvalidConfigurationException {
expectException("Config file must contain a query-select element");
readConfigFile("<list-view-config>"
+ "<template>template.ftl</template>" + "</list-view-config>");
}
@Test
public void selectQueryMultiple() throws InvalidConfigFileException {
public void selectQueryMultiple() throws InvalidConfigurationException {
expectException("Config file may not contain more than one query-select element");
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
@ -95,21 +93,21 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void selectQueryEmpty() throws InvalidConfigFileException {
public void selectQueryEmpty() throws InvalidConfigurationException {
expectException("In a config file, the <query-select> element must not be empty.");
readConfigFile("<list-view-config>" + "<query-select/>"
+ "<template>template.ftl</template>" + "</list-view-config>");
}
@Test
public void templateNameMissing() throws InvalidConfigFileException {
public void templateNameMissing() throws InvalidConfigurationException {
expectException("Config file must contain a template element");
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>" + "</list-view-config>");
}
@Test
public void templateNameMultiple() throws InvalidConfigFileException {
public void templateNameMultiple() throws InvalidConfigurationException {
expectException("Config file may not contain more than one template element");
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
@ -118,7 +116,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void templateNameEmpty() throws InvalidConfigFileException {
public void templateNameEmpty() throws InvalidConfigurationException {
expectException("In a config file, the <template> element must not be empty.");
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
@ -126,7 +124,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void postprocessorNameMultiple() throws InvalidConfigFileException {
public void postprocessorNameMultiple() throws InvalidConfigurationException {
expectException("Config file may not contain more than one postprocessor element");
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
@ -140,7 +138,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
// ----------------------------------------------------------------------
@Test
public void minimalSuccess() throws InvalidConfigFileException {
public void minimalSuccess() throws InvalidConfigurationException {
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
+ "<template>template.ftl</template>" + "</list-view-config>");
@ -149,7 +147,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void maximalSuccess() throws InvalidConfigFileException {
public void maximalSuccess() throws InvalidConfigurationException {
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
+ "<query-construct>CONSTRUCT ONE</query-construct>"
@ -163,7 +161,7 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void postprocessorEmptyIsOK() throws InvalidConfigFileException {
public void postprocessorEmptyIsOK() throws InvalidConfigurationException {
readConfigFile("<list-view-config>"
+ "<query-select>SELECT</query-select>"
+ "<query-construct>CONSTRUCT</query-construct>"
@ -174,28 +172,28 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
}
@Test
public void selectCollatedEditing() throws InvalidConfigFileException {
public void selectCollatedEditing() throws InvalidConfigurationException {
readConfigFile(XML_WITH_RICH_SELECT_CLAUSE);
assertConfigFile(true, true, "SELECT collated1 collated2 ", constructs(),
"template.ftl", "");
}
@Test
public void selectCollatedNotEditing() throws InvalidConfigFileException {
public void selectCollatedNotEditing() throws InvalidConfigurationException {
readConfigFile(XML_WITH_RICH_SELECT_CLAUSE);
assertConfigFile(true, false, "SELECT collated1 collated2 critical",
constructs(), "template.ftl", "");
}
@Test
public void selectNotCollatedEditing() throws InvalidConfigFileException {
public void selectNotCollatedEditing() throws InvalidConfigurationException {
readConfigFile(XML_WITH_RICH_SELECT_CLAUSE);
assertConfigFile(false, true, "SELECT ", constructs(),
"template.ftl", "");
}
@Test
public void selectNotCollatedNotEditing() throws InvalidConfigFileException {
public void selectNotCollatedNotEditing() throws InvalidConfigurationException {
readConfigFile(XML_WITH_RICH_SELECT_CLAUSE);
assertConfigFile(false, false, "SELECT critical", constructs(),
"template.ftl", "");
@ -215,17 +213,17 @@ public class CustomListViewConfigFileTest extends AbstractTestClass {
// ----------------------------------------------------------------------
private void expectException(String message) {
thrown.expect(InvalidConfigFileException.class);
thrown.expect(InvalidConfigurationException.class);
thrown.expectMessage(message);
}
private void expectException(Matcher<String> matcher) {
thrown.expect(InvalidConfigFileException.class);
thrown.expect(InvalidConfigurationException.class);
thrown.expectMessage(matcher);
}
private void readConfigFile(String xmlString)
throws InvalidConfigFileException {
throws InvalidConfigurationException {
StringReader reader = new StringReader(xmlString);
configFile = new CustomListViewConfigFile(reader);
}

View file

@ -18,7 +18,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Level;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@ -39,7 +38,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyTemplateModel.InvalidConfigurationException;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
import freemarker.template.Configuration;
public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@ -204,7 +204,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
throws InvalidConfigurationException {
// TODO if we can't translate the path, log the error and use the
// default.
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("fileHasNoRealPath");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -215,7 +215,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void configFileNotFound() throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("configFileDoesNotExist");
@ -233,7 +233,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void configFileNotValidXml() throws InvalidConfigurationException {
suppressSyserr();
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("notValidXml");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -248,7 +248,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void selectQueryNodeIsNotFound()
throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("selectQueryNodeNotFound");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -259,7 +259,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void selectQueryNodeIsBlank() throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("selectQueryNodeBlank");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -273,7 +273,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
//
@Test
public void templateNodeNotFound() throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("templateNodeNotFound");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -284,7 +284,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void templateNodeIsEmpty() throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("templateNodeIsEmpty");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -295,7 +295,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void templateDoesNotExist() throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("templateDoesNotExist");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -414,7 +414,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void postProcessorClassNotFound()
throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("postProcessorClassNotFound");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -428,7 +428,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void postProcessorClassIsNotSuitable()
throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("postProcessorClassNotSuitable");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -442,7 +442,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void postProcessorClassHasWrongConstructor()
throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("postProcessorWrongConstructor");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -456,7 +456,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void postProcessorConstructorThrowsAnException()
throws InvalidConfigurationException {
captureLogsFromOPTM();
captureLogsFromPropertyListConfig();
op = buildOperation("postProcessorConstructorThrowsException");
optm = new NonCollatingOPTM(op, subject, vreq, false);
@ -498,11 +498,10 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
}
/**
* Capture the log for ObjectPropertyTemplateModel and suppress it from the
* console.
* Capture the log for PropertyListConfig and suppress it from the console.
*/
private void captureLogsFromOPTM() {
captureLogOutput(ObjectPropertyTemplateModel.class, logMessages, true);
private void captureLogsFromPropertyListConfig() {
captureLogOutput(PropertyListConfig.class, logMessages, true);
}
private void assertLogMessagesContains(String message, String expected) {
@ -548,17 +547,10 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
Field configField = ObjectPropertyTemplateModel.class
.getDeclaredField("config");
configField.setAccessible(true);
Object config = configField.get(optm);
Class<?> configClass = Class
.forName("edu.cornell.mannlib.vitro.webapp.web."
+ "templatemodels.individual."
+ "ObjectPropertyTemplateModel$PropertyListConfig");
Field ppField = configClass.getDeclaredField("postprocessor");
ppField.setAccessible(true);
Object pp = ppField.get(config);
PropertyListConfig config = (PropertyListConfig) configField
.get(optm);
ObjectPropertyDataPostProcessor pp = config.getPostprocessor();
if (pp == null) {
assertNull(message + " - postprocessor is null", expected);
} else {
@ -607,7 +599,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
}
@Override
protected ConfigError checkQuery(String queryString) {
public ConfigError checkQuery(String queryString) {
return null;
}