Menu

dynamic parameter value allocation in bean

Help
Doron
2014-01-26
2014-02-04
  • Doron

    Doron - 2014-01-26

    Hi,
    i want to use the get<ParameterName>Options method to dynamically set values for a field from DB.

    my issue is using the db SO since i am trying to configure this method under a bean object i am using.

    is there a way to get the DB SO used by the test using this bean, or is my only option instanciating the db so myself thus loosing the SUT planner functionality?

     
  • Itai Agmon

    Itai Agmon - 2014-02-04

    What do you mean by a bean? Are you using the bean parameter provider? If you do, how does it interacts with the options function?
    Anyway, If everything else fails, you can just write the configuration to an external files and read it from a system object that you would implement that extends the database system object.

     
  • Doron

    Doron - 2014-02-04

    let me rephrase the question,
    how can i invoke my DB SO before running the test?
    the purpose of this is to get list of values for parameter dynamically from the DB

     
  • Hovav

    Hovav - 2014-02-04

    like this (true example I used in the past):

    private void initSetupNames() throws Exception {
        boolean prev = false;
        try {
            prev = report.isSilent();
            report.setSilent(true);
    
            boolean prevReporterVmVal = JSystemProperties.getInstance().isReporterVm();
            try {
                JSystemProperties.getInstance().setIsReporterVm(false);
                dbConn = (DbConnection) SystemManagerImpl.getInstance().getSystemObject("dbConnection");
            } finally {
                        JSystemProperties.getInstance().setIsReporterVm(prevReporterVmVal);
            }
    
            // fill the "String[] setupNames" with the returned values from the DB
        } finally {
            if (dbConn != null) {
                dbConn.close();
                dbConn = null;
            }
            report.setSilent(prev);
        }
    }
    
    public void handleUIEvent(HashMap<String, Parameter> map, String methodName) throws Exception {
    
        Parameter p = map.get("SetupName");
        if (p != null) {
            String currSut = new String(sut().getSutXml());
            if (setupNames == null || !currSut.equals(sutContent)) {
                sutContent = currSut;
                initSetupNames();
                if (setupNames == null
                        || setupNames.length == 0
                        || (setupNames.length == 1 && (setupNames[0] == null || setupNames[0].trim().equals("")))) {
                    setupNames = null;
                } else {
                    p.setValue(setupNames[0]);
                    p.setVisible(true);
                }
            }
    
            if (setupNames != null) {
                p.setAsOptions(true);
                p.setOptions(setupNames);
            }
    
            if (p.getValue() != null && !p.getValue().toString().equals(getDbShelfName())) {
                setDbShelfName(p.getValue().toString());
                p.signalToSave();
            }
    
            map.put("SetupName", p);
        }
    }
    
     

    Last edit: Hovav 2014-02-04
  • Doron

    Doron - 2014-02-04

    yes, seems like this is exactly it.
    thanks Hovav

     

Log in to post a comment.