Skip to content

Commit 8a301b8

Browse files
committed
Update test modules to latest changes in v4
Some tests were temporarily disabled and will be activated again when the Shell testing support is redesigned.
1 parent 83b559c commit 8a301b8

File tree

7 files changed

+79
-74
lines changed

7 files changed

+79
-74
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989

9090
<modules>
9191
<module>spring-shell-core</module>
92-
<!-- <module>spring-shell-test</module>-->
92+
<module>spring-shell-test</module>
9393
<module>spring-shell-autoconfigure</module>
94-
<!-- <module>spring-shell-test-autoconfigure</module>-->
94+
<module>spring-shell-test-autoconfigure</module>
9595
<!-- <module>spring-shell-docs</module>-->
96-
<!-- <module>spring-shell-dependencies</module>-->
96+
<module>spring-shell-dependencies</module>
9797
<module>spring-shell-samples</module>
9898
<module>spring-shell-starters</module>
9999
</modules>

spring-shell-test-autoconfigure/src/main/java/org/springframework/shell/test/autoconfigure/ShellTestClientAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
package org.springframework.shell.test.autoconfigure;
1717

1818
import org.jline.reader.LineReader;
19+
import org.jline.reader.Parser;
1920
import org.jline.terminal.Terminal;
2021

2122
import org.springframework.boot.autoconfigure.AutoConfiguration;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2324
import org.springframework.context.annotation.Bean;
24-
import org.springframework.shell.core.Shell;
2525
import org.springframework.shell.core.jline.PromptProvider;
2626
import org.springframework.shell.test.ShellTestClient;
2727
import org.springframework.shell.test.jediterm.terminal.ui.TerminalSession;
@@ -34,9 +34,9 @@ public class ShellTestClientAutoConfiguration {
3434

3535
@Bean
3636
@ConditionalOnMissingBean
37-
ShellTestClient shellTestClient(TerminalSession widget, Shell shell, PromptProvider promptProvider,
38-
LineReader lineReader, Terminal terminal) {
39-
return ShellTestClient.builder(widget, shell, promptProvider, lineReader, terminal).build();
37+
ShellTestClient shellTestClient(TerminalSession widget, PromptProvider promptProvider, LineReader lineReader,
38+
Terminal terminal, Parser parser) {
39+
return ShellTestClient.builder(widget, promptProvider, lineReader, terminal, parser).build();
4040
}
4141

4242
}

spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void testNonInteractive() {
9494

9595
Condition<String> emptyCondition = new Condition<>(line -> line.trim().isEmpty(), "Have only whitespace");
9696

97-
NonInteractiveShellSession session = client.nonInterative("help").run();
97+
NonInteractiveShellSession session = client.nonInteractive("help").run();
9898

9999
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
100100
List<String> lines = session.screen().lines();
@@ -109,7 +109,7 @@ void testNonInteractive() {
109109
assertThat(lines).are(emptyCondition);
110110
});
111111

112-
NonInteractiveShellSession session2 = client.nonInterative("help", "help").run();
112+
NonInteractiveShellSession session2 = client.nonInteractive("help", "help").run();
113113
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
114114
List<String> lines = session2.screen().lines();
115115
assertThat(lines).areNot(helpCondition);
@@ -124,7 +124,7 @@ void testNonInteractive() {
124124
void testNonInteractive2() {
125125
Condition<String> helloCondition = new Condition<>(line -> line.contains("hello"), "Hello has expected output");
126126

127-
NonInteractiveShellSession session = client.nonInterative("hello").run();
127+
NonInteractiveShellSession session = client.nonInteractive("hello").run();
128128

129129
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
130130
List<String> lines = session.screen().lines();

spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestPropertiesIntegrationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.shell.test.autoconfigure;
1717

18+
import org.junit.jupiter.api.Disabled;
1819
import org.junit.jupiter.api.Test;
1920

2021
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +32,7 @@
3132
*
3233
* @author Janne Valkealahti
3334
*/
35+
@Disabled
3436
@ShellTest(properties = { "spring.profiles.active=test", "spring.shell.test.terminal-width=81",
3537
"spring.shell.test.terminal-height=25" })
3638
@ContextConfiguration(classes = ExampleShellApplication.class)

spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/ShellTestTerminalDimensionsIntegrationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.shell.test.autoconfigure;
1717

18+
import org.junit.jupiter.api.Disabled;
1819
import org.junit.jupiter.api.Test;
1920

2021
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@
2425

2526
import static org.assertj.core.api.Assertions.assertThat;
2627

28+
@Disabled
2729
@ShellTest(terminalWidth = 81, terminalHeight = 25)
2830
@ContextConfiguration(classes = ExampleShellApplication.class)
2931
class ShellTestTerminalDimensionsIntegrationTests {

spring-shell-test-autoconfigure/src/test/java/org/springframework/shell/test/autoconfigure/app/ExampleShellApplication.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,22 @@
1616
package org.springframework.shell.test.autoconfigure.app;
1717

1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import org.springframework.shell.core.command.annotation.Command;
1920
import org.springframework.shell.test.autoconfigure.ShellTest;
2021

2122
/**
2223
* Example {@link SpringBootApplication @SpringBootApplication} for use with
2324
* {@link ShellTest @ShellTest} tests.
2425
*
2526
* @author Janne Valkealahti
27+
* @author Mahmoud Ben Hassine
2628
*/
2729
@SpringBootApplication
2830
public class ExampleShellApplication {
2931

32+
@Command(name = "hi", description = "Says hello")
33+
public String hello() {
34+
return "hello";
35+
}
36+
3037
}

spring-shell-test/src/main/java/org/springframework/shell/test/ShellTestClient.java

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
import java.util.concurrent.atomic.AtomicInteger;
2323

2424
import org.jline.reader.LineReader;
25+
import org.jline.reader.Parser;
2526
import org.jline.terminal.Terminal;
2627
import org.apache.commons.logging.Log;
2728
import org.apache.commons.logging.LogFactory;
2829

29-
import org.springframework.shell.core.Shell;
30+
import org.springframework.shell.core.ConsoleInputProvider;
31+
import org.springframework.shell.core.NonInteractiveShellRunner;
3032
import org.springframework.shell.core.ShellRunner;
31-
import org.springframework.shell.core.context.DefaultShellContext;
32-
import org.springframework.shell.core.jline.InteractiveShellRunner;
33-
import org.springframework.shell.core.jline.NonInteractiveShellRunner;
33+
import org.springframework.shell.core.SystemShellRunner;
34+
import org.springframework.shell.core.command.CommandRegistry;
35+
import org.springframework.shell.core.command.DefaultCommandParser;
36+
import org.springframework.shell.core.jline.JLineInputProvider;
3437
import org.springframework.shell.core.jline.PromptProvider;
3538
import org.springframework.shell.test.jediterm.terminal.ui.TerminalSession;
3639

@@ -54,7 +57,7 @@ public interface ShellTestClient extends Closeable {
5457
* @param args the command arguments
5558
* @return session for chaining
5659
*/
57-
NonInteractiveShellSession nonInterative(String... args);
60+
NonInteractiveShellSession nonInteractive(String... args);
5861

5962
/**
6063
* Read the screen.
@@ -65,27 +68,47 @@ public interface ShellTestClient extends Closeable {
6568
/**
6669
* Get an instance of a builder.
6770
* @param terminalSession the terminal session
68-
* @param shell the shell
6971
* @param promptProvider the prompt provider
7072
* @param lineReader the line reader
7173
* @param terminal the terminal
7274
* @return a Builder
7375
*/
74-
public static Builder builder(TerminalSession terminalSession, Shell shell, PromptProvider promptProvider,
75-
LineReader lineReader, Terminal terminal) {
76-
return new DefaultBuilder(terminalSession, shell, promptProvider, lineReader, terminal);
76+
static Builder builder(TerminalSession terminalSession, PromptProvider promptProvider, LineReader lineReader,
77+
Terminal terminal, Parser parser) {
78+
return new Builder(terminalSession, promptProvider, lineReader, terminal, parser);
7779
}
7880

7981
/**
8082
* Builder interface for {@code ShellClient}.
8183
*/
82-
interface Builder {
84+
class Builder {
85+
86+
private TerminalSession terminalSession;
87+
88+
private PromptProvider promptProvider;
89+
90+
private LineReader lineReader;
91+
92+
private Terminal terminal;
93+
94+
private Parser parser;
8395

8496
/**
8597
* Build a shell client.
8698
* @return a shell client
8799
*/
88-
ShellTestClient build();
100+
Builder(TerminalSession terminalSession, PromptProvider promptProvider, LineReader lineReader,
101+
Terminal terminal, Parser parser) {
102+
this.terminalSession = terminalSession;
103+
this.promptProvider = promptProvider;
104+
this.lineReader = lineReader;
105+
this.terminal = terminal;
106+
this.parser = parser;
107+
}
108+
109+
public ShellTestClient build() {
110+
return new DefaultShellClient(terminalSession, promptProvider, lineReader, terminal, parser);
111+
}
89112

90113
}
91114

@@ -128,42 +151,12 @@ interface NonInteractiveShellSession extends BaseShellSession<NonInteractiveShel
128151

129152
}
130153

131-
static class DefaultBuilder implements Builder {
132-
133-
private TerminalSession terminalSession;
134-
135-
private Shell shell;
136-
137-
private PromptProvider promptProvider;
138-
139-
private LineReader lineReader;
140-
141-
private Terminal terminal;
142-
143-
DefaultBuilder(TerminalSession terminalSession, Shell shell, PromptProvider promptProvider,
144-
LineReader lineReader, Terminal terminal) {
145-
this.terminalSession = terminalSession;
146-
this.shell = shell;
147-
this.promptProvider = promptProvider;
148-
this.lineReader = lineReader;
149-
this.terminal = terminal;
150-
}
151-
152-
@Override
153-
public ShellTestClient build() {
154-
return new DefaultShellClient(terminalSession, shell, promptProvider, lineReader, terminal);
155-
}
156-
157-
}
158-
159-
static class DefaultShellClient implements ShellTestClient {
154+
class DefaultShellClient implements ShellTestClient {
160155

161156
private final static Log log = LogFactory.getLog(DefaultShellClient.class);
162157

163158
private TerminalSession terminalSession;
164159

165-
private Shell shell;
166-
167160
private PromptProvider promptProvider;
168161

169162
private LineReader lineReader;
@@ -172,15 +165,17 @@ static class DefaultShellClient implements ShellTestClient {
172165

173166
private Terminal terminal;
174167

168+
private Parser parser;
169+
175170
private final BlockingQueue<ShellRunnerTaskData> blockingQueue = new LinkedBlockingDeque<>(10);
176171

177-
DefaultShellClient(TerminalSession terminalSession, Shell shell, PromptProvider promptProvider,
178-
LineReader lineReader, Terminal terminal) {
172+
DefaultShellClient(TerminalSession terminalSession, PromptProvider promptProvider, LineReader lineReader,
173+
Terminal terminal, Parser parser) {
179174
this.terminalSession = terminalSession;
180-
this.shell = shell;
181175
this.promptProvider = promptProvider;
182176
this.lineReader = lineReader;
183177
this.terminal = terminal;
178+
this.parser = parser;
184179
}
185180

186181
@Override
@@ -190,18 +185,18 @@ public InteractiveShellSession interactive() {
190185
runnerThread = new Thread(new ShellRunnerTask(this.blockingQueue));
191186
runnerThread.start();
192187
}
193-
return new DefaultInteractiveShellSession(shell, promptProvider, lineReader, blockingQueue, terminalSession,
188+
return new DefaultInteractiveShellSession(promptProvider, lineReader, blockingQueue, terminalSession,
194189
terminal);
195190
}
196191

197192
@Override
198-
public NonInteractiveShellSession nonInterative(String... args) {
193+
public NonInteractiveShellSession nonInteractive(String... args) {
199194
terminalSession.start();
200195
if (runnerThread == null) {
201196
runnerThread = new Thread(new ShellRunnerTask(this.blockingQueue));
202197
runnerThread.start();
203198
}
204-
return new DefaultNonInteractiveShellSession(shell, args, blockingQueue, terminalSession, terminal);
199+
return new DefaultNonInteractiveShellSession(parser, args, blockingQueue, terminalSession, terminal);
205200
}
206201

207202
@Override
@@ -221,9 +216,7 @@ public void close() throws IOException {
221216

222217
}
223218

224-
static class DefaultInteractiveShellSession implements InteractiveShellSession {
225-
226-
private Shell shell;
219+
class DefaultInteractiveShellSession implements InteractiveShellSession {
227220

228221
private PromptProvider promptProvider;
229222

@@ -237,9 +230,8 @@ static class DefaultInteractiveShellSession implements InteractiveShellSession {
237230

238231
private final AtomicInteger state = new AtomicInteger(-2);
239232

240-
public DefaultInteractiveShellSession(Shell shell, PromptProvider promptProvider, LineReader lineReader,
233+
public DefaultInteractiveShellSession(PromptProvider promptProvider, LineReader lineReader,
241234
BlockingQueue<ShellRunnerTaskData> blockingQueue, TerminalSession terminalSession, Terminal terminal) {
242-
this.shell = shell;
243235
this.promptProvider = promptProvider;
244236
this.lineReader = lineReader;
245237
this.blockingQueue = blockingQueue;
@@ -265,8 +257,10 @@ public ShellScreen screen() {
265257

266258
@Override
267259
public InteractiveShellSession run() {
268-
ShellRunner runner = new InteractiveShellRunner(lineReader, promptProvider, shell,
269-
new DefaultShellContext());
260+
JLineInputProvider inputProvider = new JLineInputProvider(lineReader);
261+
inputProvider.setPromptProvider(promptProvider);
262+
ShellRunner runner = new SystemShellRunner(new ConsoleInputProvider(), new DefaultCommandParser(),
263+
new CommandRegistry());
270264
this.blockingQueue.add(new ShellRunnerTaskData(runner, new String[] {}, state));
271265
return this;
272266
}
@@ -278,9 +272,7 @@ public boolean isComplete() {
278272

279273
}
280274

281-
static class DefaultNonInteractiveShellSession implements NonInteractiveShellSession {
282-
283-
private Shell shell;
275+
class DefaultNonInteractiveShellSession implements NonInteractiveShellSession {
284276

285277
private String[] args;
286278

@@ -290,15 +282,17 @@ static class DefaultNonInteractiveShellSession implements NonInteractiveShellSes
290282

291283
private Terminal terminal;
292284

285+
private Parser parser;
286+
293287
private final AtomicInteger state = new AtomicInteger(-2);
294288

295-
public DefaultNonInteractiveShellSession(Shell shell, String[] args,
289+
public DefaultNonInteractiveShellSession(Parser parser, String[] args,
296290
BlockingQueue<ShellRunnerTaskData> blockingQueue, TerminalSession terminalSession, Terminal terminal) {
297-
this.shell = shell;
298291
this.args = args;
299292
this.blockingQueue = blockingQueue;
300293
this.terminalSession = terminalSession;
301294
this.terminal = terminal;
295+
this.parser = parser;
302296
}
303297

304298
@Override
@@ -319,7 +313,7 @@ public ShellScreen screen() {
319313

320314
@Override
321315
public NonInteractiveShellSession run() {
322-
ShellRunner runner = new NonInteractiveShellRunner(shell, new DefaultShellContext());
316+
ShellRunner runner = new NonInteractiveShellRunner(new DefaultCommandParser(), new CommandRegistry());
323317
this.blockingQueue.add(new ShellRunnerTaskData(runner, args, state));
324318
return this;
325319
}
@@ -331,10 +325,10 @@ public boolean isComplete() {
331325

332326
}
333327

334-
static record ShellRunnerTaskData(ShellRunner runner, String[] args, AtomicInteger state) {
328+
record ShellRunnerTaskData(ShellRunner runner, String[] args, AtomicInteger state) {
335329
}
336330

337-
static class ShellRunnerTask implements Runnable {
331+
class ShellRunnerTask implements Runnable {
338332

339333
private final static Log log = LogFactory.getLog(ShellRunnerTask.class);
340334

0 commit comments

Comments
 (0)