Ask a Question

Groovy: second enum class not picked up on compilation

SOLVED
emmanuelflores
Occasional Contributor

Groovy: second enum class not picked up on compilation

Hello, I'm trying to set up a groovy script that lives in the groovy library, however I keep encountering a compilation error. 

 

The class below is called by another script to pull values from the arrays. The groovy class uses enums from other 2 other groovy classes to reference some data. All 3 classes are in the same script folder. The code looks like the following (note I've cut it down for brevity)

 

 

package somePackage
class SomeBins{

    def log
    def SomeBins(log){
        this.log = log
    }

    def firstBinColors = [
        '3+':FirstBinColorEnum.FIVE, 
        '2.5+':FirstBinColorEnum.FOUR] 
    
    def secondBinColors= [
        '3+':SecondBinColorEnum.EIGHT, 
        '2.5 - 2.75':SecondBinColorEnum.SEVEN,
        '2.0 - 2.25':SecondBinColorEnum.SIX]
    // some functionality that works... 
def getFirstBinColor(bin){ return firstBinColors[bin].getValue() }
def getSecondBinColor(bin){ return secondBinColors[bin].getValue() } }

 

The enums are very similar,but in different files in the same folder, defined as:

package somePackage

public enum FirstBinColorEnum{
    FIVE('74a9cf'),
    FOUR('a6bddb')

    private final String color;

    def FirstBinColorEnum(String color){
        this.color = color
    }

    def getValue(){
        return this.color
    }
}

and

package somePackage

public enum SecondBinColorEnum{
    EIGHT('74a9cf'),
    SEVEN('74a9cf'),
    SIX('a6bddb')

    private final String color;

    def SecondBinColorEnum(String color){
        this.color = color
    }

    def getValue(){
        return this.color
    }
}

When I try running the script an error is always thrown for SecondBinColorEnum. If I take it out, it finds FirstBinColorEnum class. The following is the error it throws

 

Thu Apr 04 17:46:21 MDT 2019: ERROR: An error occurred in the script of the Groovy Script test step [Groovy Script]:
Thu Apr 04 17:46:21 MDT 2019: ERROR: groovy.lang.MissingPropertyException: No such property: SecondBinColorEnum for class: somePackage.SomeBins
   groovy.lang.MissingPropertyException: No such property: SecondBinColorEnum for class: somePackage.SomeBins
   	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
   	at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)
   	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
   	at somePackage.SomeBins.<init>(SomeBins.groovy)

I am at a complete loss. Initially I had added the firstBinEnum class and worked great. But adding the second one, exactly the same way doesn't seem to work.

Any help from the groovy script gurus would be greatly appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
emmanuelflores
Occasional Contributor

Re: Groovy: second enum class not picked up on compilation

Well, I figured it out and I'm not sure why it works this way. 

 

In ReadyAPI I had to use the Enum class directly in a script for it to be loaded or recognized as a class. 

View solution in original post

2 REPLIES 2
emmanuelflores
Occasional Contributor

Re: Groovy: second enum class not picked up on compilation

Well, I figured it out and I'm not sure why it works this way. 

 

In ReadyAPI I had to use the Enum class directly in a script for it to be loaded or recognized as a class. 

View solution in original post

TanyaYatskovska
Community Manager

Re: Groovy: second enum class not picked up on compilation

Hi @emmanuelflores,

Thanks for sharing the solution you've found. This will help other members.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager


cancel
Showing results for 
Search instead for 
Did you mean: