/*
 * This Groovy source file was generated by the Gradle 'init' task.
 */
package org.mps_cli.gradle.plugin

import org.gradle.internal.impldep.org.glassfish.jaxb.runtime.v2.runtime.property.StructureLoaderBuilder

class LanguagesInformationExtractionTest extends TestBase {

    def "languages information extraction test"() {
        given:
        projectName = proj
        settingsFile << ""
        buildFile << "${buildPreamble()}" + '''

task printSolutionsInfo {
    dependsOn buildModel
    doLast {
        def repo = buildModel.repository
        println "all languages: ${repo.languages.collect { it.name }}"
        
        // concepts of a language
        println "jetbrains.mps.lang.core concepts: ${repo.conceptsOfLanguage("jetbrains.mps.lang.core").collect { it.shortName }.sort()}"
        println "library language concepts: ${repo.conceptsOfLanguage("mps.cli.landefs.library").collect { it.shortName }.sort()}"
        println "library language concept NotInstantiatedLibraryEntity is NOT found: ${!repo.conceptsOfLanguage("mps.cli.landefs.library").collect { it.shortName }.contains("NotInstantiatedLibraryEntity")}"
        println "people language concepts: ${repo.conceptsOfLanguage("mps.cli.landefs.people").collect { it.shortName }.sort()}"
        
        // super-concepts
        println "super-concepts of Book: ${repo.findConceptByShortName("Book").superConcepts.collect {it.shortName}.sort()}"
        println "super-concepts of Person: ${repo.findConceptByShortName("Person").superConcepts.collect {it.shortName}.sort()}"
        
        // properties of a concept
        println "properties of INamedConcept concept: ${repo.findConceptByShortName("INamedConcept").properties.sort()}"
        println "properties of LibraryEntityBase concept: ${repo.findConceptByShortName("LibraryEntityBase").properties.sort()}"
        println "properties of Book concept: ${repo.findConceptByShortName("Book").properties.sort()}"
        println "properties of Magazine concept: ${repo.findConceptByShortName("Magazine").properties.sort()}"

        // children of a concept
        println "children of Library concept: ${repo.findConceptByShortName("Library").children.sort()}"
    }
}

'''

        when:
        runTask("printSolutionsInfo")

        then:
        // check that we have the languages
        result.output.contains "all languages: [mps.cli.landefs.library, jetbrains.mps.lang.core, mps.cli.landefs.people]"

        // check that we have the concepts
        result.output.contains "jetbrains.mps.lang.core concepts: [INamedConcept]"
        result.output.contains "library language concepts: [Book, Library, LibraryEntityBase, Magazine]"
        result.output.contains "library language concept NotInstantiatedLibraryEntity is NOT found: true"
        result.output.contains "people language concepts: [Person, PersonRef, PersonsContainer]"

        // check that we properly set the super-concepts hierarchy
        result.output.contains "super-concepts of Book: [INamedConcept, LibraryEntityBase]"
        result.output.contains "super-concepts of Person: [INamedConcept]"

        // check that we have properties of concepts
        result.output.contains "properties of INamedConcept concept: [name]"
        result.output.contains "properties of LibraryEntityBase concept: [available, isbn]"
        result.output.contains "properties of Book concept: [publicationDate]"
        result.output.contains "properties of Magazine concept: [periodicity]"

        // check that we have children of concepts
        result.output.contains "children of Library concept: [entities]"


        where:
        proj                                 | _
        "mps_cli_lanuse_file_per_root"       | _
        "mps_cli_lanuse_default_persistency" | _
        "mps_cli_lanuse_binary" | _
    }
}
