Skip to content

Commit

Permalink
#1596
Browse files Browse the repository at this point in the history
- added test cases
  • Loading branch information
temi committed Jun 10, 2024
1 parent e3b56f8 commit 8cda3f7
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.apache.poi.ss.util.CellReference
import grails.web.mime.MimeType

import java.text.SimpleDateFormat
import java.util.zip.ZipEntry
Expand Down
90 changes: 90 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/MetadataServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,94 @@ class MetadataServiceSpec extends MongoSpec implements ServiceUnitTest<MetadataS
content[1][0].data.get("g")[1].i.guid == "gi5"
content[1][0].data.get("g")[1].i.outputSpeciesId != null
}

def "excelWorkbookToMap: getting content from bulk_import_example_error.xlsx should result in an error"() {
setup:
service.activityFormService = new ActivityFormService()
service.cacheService = new CacheService()
service.excelImportService = new ExcelImportService()
ActivityForm form1 = new ActivityForm(
name: 'form1',
formVersion: 1,
status: Status.ACTIVE,
publicationStatus: PublicationStatus.PUBLISHED,
type: 'Activity',
sections: [
new FormSection (
name: 'form1',
templateName: 'form1',
template: [
name: 'form1',
dataModel: [
[
name: 'a',
dataType: 'string',
label: 'A',
required: true
],
[
name: 'b',
dataType: 'list',
required: true,
columns: [
[
name: 'c',
dataType: 'stringList',
required: true
]
]
],
[
name: 'd',
dataType: 'list',
required: true,
columns: [
[
name: 'e',
dataType: 'string',
required: true
],
[
name: 'f',
dataType: 'species',
required: true
]
]
],
[
name: 'g',
dataType: 'list',
required: true,
columns: [
[
name: 'h',
dataType: 'stringList',
required: true
],
[
name: 'i',
dataType: 'species',
required: true
]
]
]
]
]
)
]
)
form1.save(flush: true, failOnError: true)
def file = new File("src/test/resources/bulk_import_example_error.xlsx").newInputStream()

when:
def content = service.excelWorkbookToMap(file, 'form1', true, null)

then:
messageSource.getMessage("bulkimport.conversionToObjectError", _, "", Locale.default) >> { code, array, msg, locale-> "Error parsing data into an object in serial number ${array[0]}" }
messageSource.getMessage("bulkimport.errorGroupBySerialNumber", _, "", Locale.default) >> { code, array, msg, locale-> "Error making nested object from multiple rows in serial number ${array[0]}" }
messageSource.getMessage("bulkimport.conversionToFormSectionError", _, "", Locale.default) >> { code, array, msg, locale-> "Error parsing data for form section (output) ${array[0]}" }
content.error != null
content.error.contains("300")
content.error.contains("55")
}
}
Binary file added src/test/resources/bulk_import_example_error.xlsx
Binary file not shown.

0 comments on commit 8cda3f7

Please sign in to comment.