cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Should it be possible to add rows to an InfoTable as part of a unit test?

dsodling
10-Marble

Should it be possible to add rows to an InfoTable as part of a unit test?

Dear all,

I hesitate to ask this because it seems like it should be a really trivial thing but I can't seem to be able solve it on my own.

I am simply trying to create a service that will remove duplicate rows from an InfoTable and as part of this endeavour I am trying to write a unit test to validate my service. The problem I have is that the InfoTable in my test never seems to have any data. I use the most obvious method (addRow) but that doesn't seem to do anything.

I'm hoping that someone can tell me what it is that I'm missing. Is this type of unit testing not possible, am I using the wrong methods or is there some other setting I have to get right in order to get this to work? My code is the following

public class PDSUtilTest {

   

    @Test

    public void test() throws Exception {


        PDSUtil instance = new PDSUtil();

        DataShapeDefinition dsd = new DataShapeDefinition();

        InfoTable data;

        InfoTable result;

       

        dsd.addFieldDefinition(new FieldDefinition("desc", BaseTypes.STRING));

        dsd.addFieldDefinition(new FieldDefinition("type", BaseTypes.STRING));

        dsd.addFieldDefinition(new FieldDefinition("time", BaseTypes.STRING));

        data = new InfoTable(dsd);

        addRow(data, "simple-alert", "A duplicate alert.", "2017-08-31 16:44");

        addRow(data, "simple-alert", "A duplicate alert.", "2017-08-31 16:44");

        addRow(data, "simple-alert", "A simple alert of some other sort sort.", "2017-08-31 16:44");

        addRow(data, "simple-alert", "A simple alert of some other sort sort.", "2017-08-31 16:45");

        System.out.println(data.getRowCount());

        for (int i = 0; i < data.getRowCount(); i++) {

            System.out.println(data.getRow(i));

        }

        result = instance.getUniqueRows(data, "type,desc,time");

        assertTrue("Expected one row to have been removed", result.getLength() == 3);

    }

    private void addRow(InfoTable data, String type, String desc, String time) throws Exception {

        int count = data.addRow(getRow(type,desc, time).clone());

        System.out.println("Count: " + count);

    }

           

    private ValueCollection getRow(String type, String desc, String time) throws Exception {

        ValueCollection row = new ValueCollection();

        row.SetStringValue("type", type);

        row.SetStringValue("desc", desc);

        row.SetStringValue("time", time);

       

        System.out.println("row: " + row);

       

        return row;

    }

}

Best regards

Daniel Södling

2 REPLIES 2
ttielebein
14-Alexandrite
(To:dsodling)

I do not think you are adding the rows correctly. Have you seen KCS Article 264656?

Maybe this is just an alternative way to do it. This line looks suspect to me:

int count = data.addRow(getRow(type,desc, time).clone());

I mean, what are you cloning it for? And these are all lowercase services, which don't always work the same way as their uppercase counterparts (see KCS Article 233460​)

Hope this helps!

Tori

addRow should be AddRow for an InfoTable

Announcements
Top Tags