Skip to content

Commit

Permalink
Add ImportData check
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad committed Feb 24, 2025
1 parent 4f40ffb commit f269d6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/org/labkey/test/tests/ApiKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.labkey.remoteapi.query.GetQueryDetailsCommand;
import org.labkey.remoteapi.query.GetQueryDetailsResponse;
import org.labkey.remoteapi.query.GetSchemasCommand;
import org.labkey.remoteapi.query.ImportDataResponse;
import org.labkey.remoteapi.query.SaveRowsResponse;
import org.labkey.remoteapi.query.SelectRowsCommand;
import org.labkey.remoteapi.query.SelectRowsResponse;
Expand Down Expand Up @@ -373,11 +374,18 @@ private void verifyValidAPIKey(Connection connection, String userEmail) throws I
assertEquals("Connection user", userEmail, whoAmI.getEmail());

QueryApiHelper queryApiHelper = new QueryApiHelper(connection, getProjectName(), "lists", LIST_NAME);

// ImportData doesn't return auth challenge. Make sure it works
ImportDataResponse importResponse = queryApiHelper.importData(LIST_VALUE + "\nvalue" + valueCount.get());
valueCount.incrementAndGet();
assertEquals("Rows imported", 1, importResponse.getRowCount());

SaveRowsResponse saveResponse = queryApiHelper.insertRows(List.of(Map.of(LIST_VALUE, "value" + valueCount.get())));
assertEquals("Rows saved", 1, saveResponse.getRowsAffected());
valueCount.incrementAndGet();
assertEquals("Rows inserted", 1, saveResponse.getRowsAffected());

SelectRowsResponse selectResponse = queryApiHelper.selectRows();
assertEquals("Total rows", valueCount.incrementAndGet(), selectResponse.getRowCount());
assertEquals("Total rows", valueCount.get(), selectResponse.getRowCount());

whoAmI = new WhoAmICommand().execute(connection, null);
assertEquals("Connection user", userEmail, whoAmI.getEmail());
Expand Down
19 changes: 19 additions & 0 deletions src/org/labkey/test/util/query/QueryApiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.labkey.remoteapi.domain.GetDomainDetailsCommand;
import org.labkey.remoteapi.query.DeleteRowsCommand;
import org.labkey.remoteapi.query.Filter;
import org.labkey.remoteapi.query.ImportDataCommand;
import org.labkey.remoteapi.query.ImportDataResponse;
import org.labkey.remoteapi.query.InsertRowsCommand;
import org.labkey.remoteapi.query.SaveRowsResponse;
import org.labkey.remoteapi.query.SelectRowsCommand;
Expand All @@ -18,6 +20,7 @@
import org.labkey.remoteapi.query.TruncateTableResponse;
import org.labkey.remoteapi.query.UpdateRowsCommand;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -97,6 +100,22 @@ public SaveRowsResponse updateRows(List<Map<String, Object>> rows) throws IOExce
return updateRowsCommand.execute(_connection, _containerPath);
}

public ImportDataResponse importData(String text) throws IOException, CommandException
{
ImportDataCommand importDataCommand = new ImportDataCommand(_schema, _query);
importDataCommand.setText(text);
importDataCommand.setTimeout(_insertTimout);
return importDataCommand.execute(_connection, _containerPath);
}

public ImportDataResponse importData(File file) throws IOException, CommandException
{
ImportDataCommand importDataCommand = new ImportDataCommand(_schema, _query);
importDataCommand.setFile(file);
importDataCommand.setTimeout(_insertTimout);
return importDataCommand.execute(_connection, _containerPath);
}

/**
* @param rowsToDelete Should include primary key(s) for the table
* @return a list of the rows that were deleted
Expand Down

0 comments on commit f269d6b

Please sign in to comment.