PageRenderTime 168ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/uk/ac/manchester/cs/owl/semspreadsheets/model/xssf/impl/SheetXSSFImplTest.java

https://github.com/semantalytics/RightField
Java | 86 lines | 64 code | 19 blank | 3 comment | 0 complexity | 17bc9ba3e53af1b2b9a649879a6b3202 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package uk.ac.manchester.cs.owl.semspreadsheets.model.xssf.impl;
  2. import static org.junit.Assert.assertEquals;
  3. import java.util.List;
  4. import org.apache.poi.ss.usermodel.DataValidation;
  5. import org.apache.poi.ss.usermodel.DataValidationConstraint;
  6. import org.apache.poi.ss.usermodel.DataValidationHelper;
  7. import org.apache.poi.ss.util.CellRangeAddress;
  8. import org.apache.poi.ss.util.CellRangeAddressList;
  9. import org.apache.poi.xssf.usermodel.XSSFDataValidation;
  10. import org.apache.poi.xssf.usermodel.XSSFSheet;
  11. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  12. import org.junit.Test;
  13. import uk.ac.manchester.cs.owl.semspreadsheets.DocumentsCatalogue;
  14. import uk.ac.manchester.cs.owl.semspreadsheets.SpreadsheetTestHelper;
  15. import uk.ac.manchester.cs.owl.semspreadsheets.model.Sheet;
  16. import uk.ac.manchester.cs.owl.semspreadsheets.model.Workbook;
  17. import uk.ac.manchester.cs.owl.semspreadsheets.model.impl.GeneralSheetTests;
  18. public class SheetXSSFImplTest extends GeneralSheetTests {
  19. @Test
  20. public void testGetValidationData() throws Exception {
  21. SheetXSSFImpl sheet = (SheetXSSFImpl)getTestSheet();
  22. List<XSSFDataValidation> validationData = sheet.getValidationData();
  23. assertEquals(1,validationData.size());
  24. XSSFDataValidation val = validationData.get(0);
  25. CellRangeAddress[] cellRangeAddresses = val.getRegions().getCellRangeAddresses();
  26. assertEquals(1,cellRangeAddresses.length);
  27. CellRangeAddress rangeAddresses = cellRangeAddresses[0];
  28. assertEquals(4,rangeAddresses.getFirstColumn());
  29. assertEquals(4,rangeAddresses.getLastColumn());
  30. assertEquals(11,rangeAddresses.getFirstRow());
  31. assertEquals(11,rangeAddresses.getLastRow());
  32. }
  33. @Test
  34. public void testGettingValidationsAfterAddingCustomInPOI() throws Exception {
  35. XSSFWorkbook wb = new XSSFWorkbook();
  36. XSSFSheet sheet = wb.createSheet();
  37. List<XSSFDataValidation> dataValidations = sheet.getDataValidations(); //<-- works
  38. assertEquals(0, dataValidations.size());
  39. //create the cell that will have the validation applied
  40. sheet.createRow(0).createCell(0);
  41. DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
  42. DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("SUM($A$1:$A$1) <= 3500");
  43. CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
  44. DataValidation validation = dataValidationHelper.createValidation(constraint, addressList);
  45. sheet.addValidationData(validation);
  46. dataValidations = sheet.getDataValidations(); //<-- raised XmlValueOutOfRangeException
  47. assertEquals(1, dataValidations.size());
  48. }
  49. //opens the workbook src/test/resources/simple_annotated_book.xls
  50. protected Workbook getTestWorkbook() throws Exception {
  51. return SpreadsheetTestHelper.openWorkbookXSSF(DocumentsCatalogue.simpleAnnotatedXLSXWorkbookURI());
  52. }
  53. //opens the first sheet from test workbook src/test/resources/simple_annotated_sheet.xls used for most of these tests
  54. protected Sheet getTestSheet() throws Exception {
  55. return (SheetXSSFImpl)getTestWorkbook().getSheet(0);
  56. }
  57. protected Workbook getBlankWorkbook() throws Exception {
  58. return SpreadsheetTestHelper.getBlankXSSFWorkbook();
  59. }
  60. protected Sheet getBlankSheet() throws Exception {
  61. return SpreadsheetTestHelper.getBlankXSSFWorkbook().createSheet();
  62. }
  63. @Override
  64. protected Sheet getTestSheetWithProperties() throws Exception {
  65. return SpreadsheetTestHelper.getWorkbookSheetXSSF(DocumentsCatalogue.bookWithPropertiesXLSXURI(), 0);
  66. }
  67. }