Skip to content

Commit 431173e

Browse files
committed
Run function tests. Load from json-files inputs for function tests.
1 parent 502857c commit 431173e

File tree

9 files changed

+231
-58
lines changed

9 files changed

+231
-58
lines changed

sources/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
<change-notes><![CDATA[
1414
<ul>
15+
<li>1.2 RC3</li>
16+
<li>Run function tests.</li>
17+
<li>Load from json-files inputs for function tests.</li>
1518
<li>1.2 RC2</li>
1619
<li>Changed the layout, added tabs and a toolbar.</li>
1720
<li>Saved last selected functions and JAR-artifacts.</li>
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.github.satr.idea.plugin.connector.la.entities;
2+
3+
public class TestFunctionInputEntry {
4+
private String filePath;
5+
private final String fileName;
6+
private final String inputText;
7+
8+
public TestFunctionInputEntry(String filePath, String fileName, String inputText) {
9+
this.filePath = filePath;
10+
this.fileName = fileName;
11+
this.inputText = inputText;
12+
}
13+
14+
public String getFilePath() {
15+
return filePath;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return String.format("%s (%s)", fileName, filePath);
21+
}
22+
23+
public String getInputText() {
24+
return inputText;
25+
}
26+
27+
public String getFileName() {
28+
return fileName;
29+
}
30+
}

sources/src/io/github/satr/idea/plugin/connector/la/models/ConnectorSettings.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ConnectorSettings implements PersistentStateComponent<ConnectorSet
2121
private String lastSelectedJarArtifactName;
2222
private String lastSelectedRegionName;
2323
private String lastSelectedCredentialProfile;
24+
private String lastSelectedTestFunctionInputFilePath;
2425

2526
public String getLastSelectedJarArtifactName() {
2627
return lastSelectedJarArtifactName;
@@ -84,4 +85,12 @@ public String getLastSelectedCredentialProfile() {
8485
public void setLastSelectedCredentialProfile(String lastSelectedCredentialProfile) {
8586
this.lastSelectedCredentialProfile = lastSelectedCredentialProfile;
8687
}
88+
89+
public String getLastSelectedTestFunctionInputFilePath() {
90+
return this.lastSelectedTestFunctionInputFilePath;
91+
}
92+
93+
public void setLastSelectedTestFunctionInputFilePath(String path) {
94+
this.lastSelectedTestFunctionInputFilePath = path;
95+
}
8796
}

sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// Copyright © 2017, github.com/satr, MIT License
33

44
import com.intellij.openapi.project.Project;
5-
import io.github.satr.idea.plugin.connector.la.entities.ArtifactEntry;
6-
import io.github.satr.idea.plugin.connector.la.entities.CredentialProfileEntry;
7-
import io.github.satr.idea.plugin.connector.la.entities.FunctionEntry;
8-
import io.github.satr.idea.plugin.connector.la.entities.RegionEntry;
5+
import io.github.satr.idea.plugin.connector.la.entities.*;
6+
7+
import java.io.File;
98

109
public interface ConnectorPresenter {
1110
void setView(ConnectorView view);
@@ -22,5 +21,8 @@ public interface ConnectorPresenter {
2221
void setFunction(FunctionEntry functionEntry);
2322
void setJarArtifact(ArtifactEntry artifactEntry);
2423
void runFunctionTest(Project project, String text);
25-
void openFunctionTestInputFile(String filename);
24+
void openTestFunctionInputFile(File filename);
25+
String getLastSelectedTestFunctionInputFilePath();
26+
void setLastSelectedTestFunctionInputFilePath(String path);
27+
void setSetTestFunctionInputFromRecent(TestFunctionInputEntry entry);
2628
}

sources/src/io/github/satr/idea/plugin/connector/la/ui/ConnectorPresenterImpl.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import com.intellij.openapi.components.ServiceManager;
88
import com.intellij.openapi.project.Project;
99
import io.github.satr.common.*;
10-
import io.github.satr.idea.plugin.connector.la.entities.ArtifactEntry;
11-
import io.github.satr.idea.plugin.connector.la.entities.CredentialProfileEntry;
12-
import io.github.satr.idea.plugin.connector.la.entities.FunctionEntry;
13-
import io.github.satr.idea.plugin.connector.la.entities.RegionEntry;
10+
import io.github.satr.idea.plugin.connector.la.entities.*;
1411
import io.github.satr.idea.plugin.connector.la.models.ConnectorSettings;
1512
import io.github.satr.idea.plugin.connector.la.models.ProjectModel;
1613
import org.jetbrains.annotations.NotNull;
1714

1815
import java.io.File;
16+
import java.nio.file.Files;
1917
import java.util.ArrayList;
2018
import java.util.Collection;
21-
import java.util.Date;
2219
import java.util.List;
2320

2421
import static org.apache.http.util.TextUtils.isEmpty;
@@ -27,6 +24,7 @@ public class ConnectorPresenterImpl extends AbstractConnectorPresenter implement
2724
private final Regions DEFAULT_REGION = Regions.US_EAST_1;
2825
private ConnectorSettings connectorSettings = ConnectorSettings.getInstance();
2926
private ConnectorView view;
27+
private List<TestFunctionInputEntry> testFunctionInputRecentEntryList = new ArrayList<>();
3028

3129
@Override
3230
public void setView(ConnectorView view) {
@@ -261,9 +259,41 @@ public void runFunctionTest(Project project, String inputText) {
261259
}
262260

263261
@Override
264-
public void openFunctionTestInputFile(String filename) {
265-
view.logDebug("Read function test input from file: %s", filename);
266-
view.setFunctionTestInput("input from file:" + filename);
262+
public void openTestFunctionInputFile(File file) {
263+
try {
264+
String filePath = file.getCanonicalPath();
265+
view.logDebug("Read function test input from file: %s", filePath);
266+
byte[] buffer = Files.readAllBytes(file.toPath());
267+
String inputText = new String(buffer);
268+
view.setTestFunctionInput(inputText);
269+
for(TestFunctionInputEntry entry : testFunctionInputRecentEntryList){
270+
if(entry.getFilePath().equals(filePath)){
271+
testFunctionInputRecentEntryList.remove(entry);
272+
break;
273+
}
274+
}
275+
testFunctionInputRecentEntryList.add(new TestFunctionInputEntry(filePath, file.getName(), inputText));
276+
view.setTestFunctionInputRecentEntryList(testFunctionInputRecentEntryList);
277+
} catch (Exception e) {
278+
e.printStackTrace();
279+
view.logError(e);
280+
}
281+
}
282+
283+
@Override
284+
public String getLastSelectedTestFunctionInputFilePath() {
285+
String filePath = connectorSettings.getLastSelectedTestFunctionInputFilePath();
286+
return isEmpty(filePath) ? "" : filePath;
287+
}
288+
289+
@Override
290+
public void setLastSelectedTestFunctionInputFilePath(String path) {
291+
connectorSettings.setLastSelectedTestFunctionInputFilePath(path);
292+
}
293+
294+
@Override
295+
public void setSetTestFunctionInputFromRecent(TestFunctionInputEntry entry) {
296+
view.setTestFunctionInput(entry.getInputText());
267297
}
268298

269299
private Regions tryGetRegionBy(String regionName) {

0 commit comments

Comments
 (0)