Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 4780

Show
Ignore:
Timestamp:
07/02/08 14:10:29 (2 months ago)
Author:
r0bby
Message:

groovyforms: revert tests back since i moved the syntax checking back to my utility class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/groovyforms/src/org/openmrs/module/groovyforms/util/GroovyFormsClassUtil.groovy

    r4746 r4780  
    1515 
    1616import org.apache.commons.logging.LogFactory 
     17import org.codehaus.groovy.control.CompilationFailedException 
    1718import org.openmrs.module.groovyforms.metadata.model.GroovyFormsDomainModelMetaData 
     19import org.openmrs.util.OpenmrsClassLoader 
    1820 
    1921/* 
     
    7476        f 
    7577    } 
     78    static def getClassLoader() { 
     79        def gcl = new GroovyClassLoader(OpenmrsClassLoader.getInstance()) 
     80        gcl 
     81    } 
     82 
     83    /** 
     84     * This method is used to relay errors to the user 
     85     * @param clazz  the class 
     86     * @return the exception message or null if it was successful 
     87     */ 
     88    static def checkSyntax(clazz) { 
     89        def sb = new StringBuilder() 
     90        sb << "import org.openmrs.*\n\n\n" 
     91        sb << clazz 
     92        def res = null 
     93        try { 
     94            getClassLoader().parseClass(sb.toString()) 
     95 
     96        } catch (CompilationFailedException e) { 
     97            res = "Exception: ${e.message}" 
     98        } 
     99        res 
     100 
     101    } 
     102 
     103    /** 
     104     * Check if it is result groovy code. 
     105     * @param clazz the class 
     106     * @return whether or not it is result groovy code 
     107     */ 
     108    static def isresultGroovy(clazz) { 
     109        def sb = new StringBuilder() 
     110        sb << "import org.openmrs.*\n\n\n" 
     111        sb << clazz 
     112        try { 
     113            getClassLoader().parseClass(sb.toString()) 
     114        } catch (CompilationFailedException e) { 
     115            return false 
     116        } 
     117        return true 
     118    } 
    76119} 
  • openmrs-modules/groovyforms/test/org/openmrs/module/groovyforms/GroovyFormClassUtilTest.groovy

    r4746 r4780  
    1414package org.openmrs.module.groovyforms 
    1515 
    16 import org.openmrs.module.groovyforms.util.GroovyFormsClassUtil as GCU 
    17  
    1816import static org.junit.Assert.assertEquals 
    1917import org.junit.Test 
     
    2119import org.openmrs.Patient 
    2220import org.openmrs.module.groovyforms.metadata.model.GroovyFormsDomainModelMetaData 
     21import org.openmrs.module.groovyforms.util.GroovyFormsClassUtil 
    2322 
    24 class GroovyClassUtilTest { 
     23 
     24class GroovyFormsClassUtilTest { 
    2525 
    2626 
    2727    @Test 
    2828    void testProcessClass() { 
    29         def model = GCU.getProperties(new Foo()) 
     29        def model = GroovyFormsClassUtil.getProperties(new Foo()) 
    3030        GroovyFormsDomainModelMetaData bar = model[0] 
    3131        GroovyFormsDomainModelMetaData x = model[1] 
     
    4242    @Test 
    4343    void testNoPropertiesFound() { 
    44         def model = GCU.getProperties(new Bar()) 
     44        def model = GroovyFormsClassUtil.getProperties(new Bar()) 
    4545        assertEquals(model, null); 
    4646    } 
     
    4848    @Test 
    4949    void testValidClass() { 
    50         assertTrue GCU.isValidGroovy('class Form { String str }') 
     50        assertTrue GroovyFormsClassUtil.isValidGroovy('class Form { String str }') 
    5151    } 
    5252 
    5353    @Test 
    5454    void testValidClassWithOpenMRSModelClasses() { 
    55         assertTrue GCU.isValidGroovy("class MyForm { Patient p; Concept c }") 
     55        assertTrue GroovyFormsClassUtil.isValidGroovy("class MyForm { Patient p; Concept c }") 
    5656    } 
    5757 
     
    5959    void testInvalidClass() { 
    6060        // no closing semi-colon 
    61         assertFalse GCU.isValidGroovy("class Form { ") 
     61        assertFalse GroovyFormsClassUtil.isValidGroovy("class Form { ") 
    6262 
    6363        // no semi-colon whatsoever 
    64         assertFalse GCU.isValidGroovy("class Foo") 
     64        assertFalse GroovyFormsClassUtil.isValidGroovy("class Foo") 
    6565 
    6666        // missing name for field 
    67         assertFalse GCU.isValidGroovy("class Foo { String } ") 
     67        assertFalse GroovyFormsClassUtil.isValidGroovy("class Foo { String } ") 
    6868 
    6969    } 
  • openmrs-modules/groovyforms/web/src/org/openmrs/module/groovyforms/web/CreateGroovyFormServlet.groovy

    r4764 r4780  
    1919import javax.servlet.http.HttpServletResponse 
    2020import org.apache.commons.logging.LogFactory 
    21 import org.codehaus.groovy.control.CompilationFailedException 
     21import org.openmrs.module.groovyforms.util.GroovyFormsClassUtil 
    2222 
    2323class CreateGroovyFormServlet extends HttpServlet { 
    24     def shell 
    2524    static final def log = LogFactory.getLog(CreateGroovyFormServlet.class) 
    26     private static final long serialVersionUID = 066373513262051L 
     25    static final long serialVersionUID = 066373513262051L 
    2726 
    2827    @Override 
     
    3433        def name = request.getParameter("formName") 
    3534        def version = request.getParameter("version") 
    36         def res = this.checkSyntax(clazz) 
     35        def res = GroovyFormsClassUtil.checkSyntax(clazz) 
    3736        if (clazz) { 
    38             if (checkSyntax(clazz)) { 
     37            if (res) { 
    3938                response.contentType = "text/xml" 
    4039                response.setHeader "Cache-Conrol", "no-cache" 
     
    6160        if (log.infoEnabled) 
    6261            log.info("Initializing...") 
    63         shell = getClassLoader() 
    64     } 
    65  
    66     def getClassLoader() { 
    67         def gcl = new GroovyClassLoader(this.getClass().getClassLoader()) 
    68         gcl 
    69     } 
    70  
    71     /** 
    72      * This method is used to relay errors to the user 
    73      * @oaram clazz  the class 
    74      * @return the exception message or null if it was successful 
    75      */ 
    76     def checkSyntax(clazz) { 
    77         def sb = new StringBuilder() 
    78         sb << "import org.openmrs.*\n\n\n" 
    79         sb << clazz 
    80         def res = null 
    81         try { 
    82             getClassLoader().parseClass(sb.toString()) 
    83  
    84         } catch (CompilationFailedException e) { 
    85             res = "Exception: ${e.message}" 
    86         } 
    87         res 
    88  
    89     } 
    90  
    91     /** 
    92      * Check if it is result groovy code. 
    93      * @param clazz the class 
    94      * @return whether or not it is result groovy code 
    95      */ 
    96     def isresultGroovy(clazz) { 
    97         def sb = new StringBuilder() 
    98         sb << "import org.openmrs.*\n\n\n" 
    99         sb << clazz 
    100         try { 
    101             getClassLoader().parseClass(sb.toString()) 
    102         } catch (CompilationFailedException e) { 
    103             return false 
    104         } 
    105         return true 
     62        classLoader = GroovyFormsClassUtil.getClassLoader() 
    10663    } 
    10764}