Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joneug committed Dec 16, 2020
1 parent b50fa8e commit af74d9b
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ class MdalLanguageServerTest extends AbstractLanguageServerTest {
initialize()

val file = 'seminar.mdal'.writeFile("")
file.open(ExampleContentGenerator.generateMinimalModel.toString)
file.open('''
solution "Seminar Management" {
Prefix = "SEM";
master "Seminar" {
ShortName = "Sem.";
fields {
template("Description"; Description)
}
}
}
''')
val diagnostics = diagnostics.get(file)
assertTrue('''Unexpected errors: «diagnostics»''', diagnostics.empty)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
package de.joneug.mdal.util

class ExampleContentGenerator {

static def generateMinimalModel() '''
solution "Seminar Management" {
Prefix = "SEM";

master "Seminar" {
ShortName = "Sem.";

fields {
template("Description"; Description)
field("Duration Days"; Decimal)
template("Dimensions"; Dimensions)
}

cardPage {
group("General") {
field("Description")
field("Duration Days")
}
group("Posting Details") {
field("Dimensions")
}
}

listPage {
field("Description")
field("Duration Days")
}
}
}
'''

static def generateCorrectModel() '''
solution "Seminar Management" {
Expand Down
72 changes: 69 additions & 3 deletions de.joneug.mdal/src/test/java/de/joneug/mdal/MdalParsingTest.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,74 @@ class MdalParsingTest {
@Inject extension ValidationTestHelper

@Test
def void testMinimalModel() {
val model = parseHelper.parse(ExampleContentGenerator.generateMinimalModel)
def void testOnlyMaster() {
val model = parseHelper.parse('''
solution "Seminar Management" {
Prefix = "SEM";
master "Seminar" {
ShortName = "Sem.";
fields {
template("Description"; Description)
}
}
}
''')

assertNotNull(model)
val errors = model.eResource.errors
assertTrue('''Unexpected errors: «errors.join(", ")»''', errors.isEmpty)
model.assertNoIssues
}

@Test
def void testOnlySupplemental() {
val model = parseHelper.parse('''
solution "Seminar Management" {
Prefix = "SEM";
supplemental "Seminar Room" {
ShortName = "Sem. Room";
fields {
template("Name"; Name)
}
}
}
''')

assertNotNull(model)
val errors = model.eResource.errors
assertTrue('''Unexpected errors: «errors.join(", ")»''', errors.isEmpty)
model.assertNoIssues
}

@Test
def void testMasterDocument() {
val model = parseHelper.parse('''
solution "Seminar Management" {
Prefix = "SEM";
master "Seminar" {
ShortName = "Sem.";
fields {
template("Description"; Description)
}
}
document "Seminar Registration" {
ShortName = "Sem. Reg.";
header "Seminar Registration Header" {
ShortName = "Sem. Reg. Header";
StatusCaptions = ["Planning", "Registration", "Closed", "Canceled"];
fields {
field("Starting Date"; Date)
}
}
line "Seminar Registration Line" {
ShortName = "Sem. Reg. Line";
fields {
field("Bill-to Customer No."; Code[20])
}
}
}
}
''')

assertNotNull(model)
val errors = model.eResource.errors
Expand All @@ -55,7 +121,7 @@ class MdalParsingTest {
}

@Test
def void testModelWithIssues() {
def void testModelWithErrors() {
val model = parseHelper.parse(ExampleContentGenerator.generateModelWithErrors)
assertNotNull(model)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.eclipse.xtext.generator.InMemoryFileSystemAccess
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith
Expand All @@ -30,7 +31,7 @@ class MdalGeneratorTest {
MdalGenerator generator

InMemoryFileSystemAccess fsa

GeneratorManagement management

@BeforeEach
Expand All @@ -39,11 +40,106 @@ class MdalGeneratorTest {
this.fsa = new InMemoryFileSystemAccess()
fsa.generateFile('app.json', ExampleContentGenerator.generateAppJson)
this.management = GeneratorManagement.getInstance()
this.management.initializeFileSystemAccess(fsa)
this.management.initializeFileSystemAccess(fsa)
}

@Test
def void testOnlyMaster() {
doGenerate('''
solution "Seminar Management" {
Prefix = "SEM";
master "Seminar" {
ShortName = "Sem.";
fields {
template("Description"; Description)
}
}
}
''')
checkFileExists("EnumExt/SEMCommentLineTableNameExt.EnumExt.al")
checkFileExists("Page/SEMSeminarCard.Page.al")
checkFileExists("Page/SEMSeminarList.Page.al")
checkFileExists("Page/SEMSeminarSetup.Page.al")
checkFileExists("Table/SEMSeminar.Table.al")
checkFileExists("Table/SEMSeminarSetup.Table.al")
checkFileExists("TableExt/SEMCommentLineExt.TableExt.al")
}

@Test
def void testOnlySupplemental() {
doGenerate('''
solution "Seminar Management" {
Prefix = "SEM";
supplemental "Seminar Room" {
ShortName = "Sem. Room";
fields {
template("Name"; Name)
}
}
}
''')
checkFileExists("Page/SEMSeminarRooms.Page.al")
checkFileExists("Table/SEMSeminarRoom.Table.al")
}

@Test
def void testMasterDocument() {
doGenerate('''
solution "Seminar Management" {
Prefix = "SEM";
master "Seminar" {
ShortName = "Sem.";
fields {
template("Description"; Description)
}
}
document "Seminar Registration" {
ShortName = "Sem. Reg.";
header "Seminar Registration Header" {
ShortName = "Sem. Reg. Header";
StatusCaptions = ["Planning", "Registration", "Closed", "Canceled"];
fields {
field("Starting Date"; Date)
}
}
line "Seminar Registration Line" {
ShortName = "Sem. Reg. Line";
fields {
field("Bill-to Customer No."; Code[20])
}
}
}
}
''')
checkFileExists("Codeunit/SEMNavigateEventSub.Codeunit.al")
checkFileExists("Enum/SEMSeminarCommentDocumentType.Enum.al")
checkFileExists("Enum/SEMSemRegStatus.Enum.al")
checkFileExists("EnumExt/SEMCommentLineTableNameExt.EnumExt.al")
checkFileExists("Page/SEMPostedSemReg.Page.al")
checkFileExists("Page/SEMPostedSemRegList.Page.al")
checkFileExists("Page/SEMPostedSemRegSubf.Page.al")
checkFileExists("Page/SEMSeminarCard.Page.al")
checkFileExists("Page/SEMSeminarCommentList.Page.al")
checkFileExists("Page/SEMSeminarCommentSheet.Page.al")
checkFileExists("Page/SEMSeminarList.Page.al")
checkFileExists("Page/SEMSeminarRegistration.Page.al")
checkFileExists("Page/SEMSeminarRegistrationList.Page.al")
checkFileExists("Page/SEMSeminarSetup.Page.al")
checkFileExists("Page/SEMSemRegSubf.Page.al")
checkFileExists("PageExt/SEMSourceCodeSetupExt.PageExt.al")
checkFileExists("Table/SEMPstdSemRegHeader.Table.al")
checkFileExists("Table/SEMPstdSemRegLine.Table.al")
checkFileExists("Table/SEMSeminar.Table.al")
checkFileExists("Table/SEMSeminarCommentLine.Table.al")
checkFileExists("Table/SEMSeminarSetup.Table.al")
checkFileExists("Table/SEMSemRegHeader.Table.al")
checkFileExists("Table/SEMSemRegLine.Table.al")
checkFileExists("TableExt/SEMCommentLineExt.TableExt.al")
checkFileExists("TableExt/SEMSourceCodeSetupExt.TableExt.al")
}

@Test
def void testDoGenerate() {
def void testCorrectModel() {
doGenerate(ExampleContentGenerator.generateCorrectModel.toString)

// Tables
Expand Down Expand Up @@ -72,7 +168,7 @@ class MdalGeneratorTest {
'local procedure OnAfterGetSemSetup(var SemSetup: Record "SEM Seminar Setup")'
]
)

// Pages
checkFileContains(
"Page/SEMSeminarSetup.Page.al",
Expand All @@ -86,6 +182,13 @@ class MdalGeneratorTest {
)
}

@Test
def void testIncorrectModel() {
Assertions.assertThrows(IllegalArgumentException, [
doGenerate(ExampleContentGenerator.generateModelWithErrors.toString)
])
}

def doGenerate(String modelString) {
val model = parseHelper.parse(modelString)
logDebug(model.dump())
Expand All @@ -111,9 +214,10 @@ class MdalGeneratorTest {
logDebug(fsa.getFileInDefaultOutput(filePath))
val fileContents = fsa.getFileInDefaultOutput(filePath).toString
expectedContents.forEach[
assertTrue('''File at path "«filePath»" doesn't contain the expected content "«it»"".''', fileContents.contains(it))
expectedContents.forEach [
assertTrue('''File at path "«filePath»" doesn't contain the expected content "«it»"".''',
fileContents.contains(it))
]
}

Expand Down

0 comments on commit af74d9b

Please sign in to comment.