Skip to content

Commit c8707c6

Browse files
authored
Add boot version to app info shell command (spring-attic#5351)
* Add boot version to `app info` shell command - Update related tests to Junit5 See spring-attic#5239 * Reduce test duplication
1 parent d270ca7 commit c8707c6

File tree

12 files changed

+155
-76
lines changed

12 files changed

+155
-76
lines changed

spring-cloud-dataflow-docs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<description>Spring Cloud Data Flow Docs</description>
1313
<properties>
1414
<main.basedir>${basedir}/..</main.basedir>
15-
<docs.resources.version>0.2.1.RELEASE</docs.resources.version>
15+
<docs.resources.version>0.2.5</docs.resources.version>
1616
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
1717
</properties>
1818
<dependencies>

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/command/AppRegistryCommands.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public TablesInfo info(
143143
if (info.getShortDescription() != null) {
144144
result.addHeader(info.getShortDescription());
145145
}
146+
if (info.getBootVersion() != null) {
147+
result.addHeader(String.format("Boot version: %s:", info.getBootVersion().getBootVersion()));
148+
}
146149
if (options == null) {
147150
result.addHeader("Application options metadata is not available");
148151
}

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/AbstractShellIntegrationTest.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package org.springframework.cloud.dataflow.shell;
1818

19-
import org.junit.AfterClass;
20-
import org.junit.BeforeClass;
21-
import org.junit.Rule;
22-
import org.junit.rules.TestName;
19+
import org.junit.jupiter.api.AfterAll;
20+
import org.junit.jupiter.api.BeforeAll;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.TestInfo;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525

@@ -100,10 +100,14 @@ public abstract class AbstractShellIntegrationTest {
100100
/**
101101
* Used to capture currently executing test method.
102102
*/
103-
@Rule
104-
public TestName name = new TestName();
103+
public TestInfo testInfo;
105104

106-
@BeforeClass
105+
@BeforeEach
106+
void prepareTest(TestInfo testInfo) {
107+
this.testInfo = testInfo;
108+
}
109+
110+
@BeforeAll
107111
public static void startUp() {
108112
if (applicationContext == null) {
109113
shutdownAfterRun = Boolean.parseBoolean(System.getProperty(SHUTDOWN_AFTER_RUN, "false"));
@@ -124,7 +128,7 @@ public static void startUp() {
124128
}
125129
}
126130

127-
@AfterClass
131+
@AfterAll
128132
public static void shutdown() {
129133
if (shutdownAfterRun && applicationContext != null) {
130134
logger.info("Stopping Data Flow Server");
@@ -215,7 +219,8 @@ protected String generateUniqueStreamOrTaskName(String name) {
215219
* @return unique random stream/task name
216220
*/
217221
protected String generateUniqueStreamOrTaskName() {
218-
return generateUniqueStreamOrTaskName(name.getMethodName().replace('[', '-').replace("]", ""));
222+
return generateUniqueStreamOrTaskName(testInfo.getTestMethod().get().getName()
223+
.replace('[', '-').replace("]", ""));
219224
}
220225

221226
}

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/ShellCommandsTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

27-
import org.junit.After;
28-
import org.junit.Before;
29-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterEach;
28+
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Test;
3030

3131
import org.springframework.boot.Banner;
3232
import org.springframework.boot.WebApplicationType;
@@ -57,8 +57,8 @@
5757
*/
5858
public class ShellCommandsTests extends AbstractShellIntegrationTest {
5959

60-
@After
61-
@Before
60+
@AfterEach
61+
@BeforeEach
6262
public void unregisterAll() {
6363
AppRegistryService registry = applicationContext.getBean(AppRegistryService.class);
6464
for (AppRegistration appReg : registry.findAll()) {

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/AppRegistryCommandsTests.java

Lines changed: 101 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Test;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Nested;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.ValueSource;
2528
import org.slf4j.Logger;
2629
import org.slf4j.LoggerFactory;
2730

@@ -31,6 +34,7 @@
3134
import org.springframework.cloud.dataflow.registry.service.AppRegistryService;
3235
import org.springframework.cloud.dataflow.shell.AbstractShellIntegrationTest;
3336
import org.springframework.cloud.dataflow.shell.ShellCommandRunner;
37+
import org.springframework.cloud.dataflow.shell.command.support.TablesInfo;
3438

3539
import static org.assertj.core.api.Assertions.assertThat;
3640

@@ -48,14 +52,14 @@ public class AppRegistryCommandsTests extends AbstractShellIntegrationTest {
4852
private ShellCommandRunner commandRunner;
4953
private List<AppRegistration> registeredApps;
5054

51-
@Before
55+
@BeforeEach
5256
public void prepareForTest() {
5357
registeredApps = new ArrayList<>();
5458
registry = applicationContext.getBean(AppRegistryService.class);
5559
commandRunner = commandRunner().withValidateCommandSuccess();
5660
}
5761

58-
@After
62+
@AfterEach
5963
public void unregisterApps() {
6064
registeredApps.forEach(this::safeDeleteAppRegistration);
6165
}
@@ -68,38 +72,6 @@ private void safeDeleteAppRegistration(AppRegistration registration) {
6872
}
6973
}
7074

71-
@Test
72-
public void testRegisterTaskAppNoBootVersion() {
73-
AppRegistration registration = registerTimestampTask("timestamp", "3.2.0", "", false);
74-
assertThat(registration.getVersion()).isEqualTo("3.2.0");
75-
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.defaultVersion());
76-
}
77-
78-
@Test
79-
public void testRegisterTaskAppBootVersion2() {
80-
AppRegistration registration = registerTimestampTask("timestamp2", "3.2.0", "--bootVersion 2", false);
81-
assertThat(registration.getVersion()).isEqualTo("3.2.0");
82-
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT2);
83-
}
84-
85-
@Test
86-
public void testRegisterTaskAppBootVersion3() {
87-
AppRegistration registration = registerTimestampTask("timestamp3", "3.2.1", "--bootVersion 3", false);
88-
assertThat(registration.getVersion()).isEqualTo("3.2.1");
89-
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT3);
90-
}
91-
92-
@Test
93-
public void testRegisterTaskUpdateBootVersion3() {
94-
AppRegistration registration = registerTimestampTask("timestamp2to3", "3.2.0", "-b 2", false);
95-
assertThat(registration.getVersion()).isEqualTo("3.2.0");
96-
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT2);
97-
// The 'force=true' signals to udpate the existing 'timestamp2to3' app
98-
registration = registerTimestampTask("timestamp2to3", "3.2.1", "-b 3", true);
99-
assertThat(registration.getVersion()).isEqualTo("3.2.1");
100-
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT3);
101-
}
102-
10375
private AppRegistration registerTimestampTask(String name, String timestampArtifactVersion, String bootVersionOption, boolean force) {
10476
String commandTemplate = "app register --type task --name %s %s %s --uri maven://org.springframework.cloud.task.app:task-timestamp:%s";
10577
String command = String.format(commandTemplate, name, bootVersionOption, (force ? "--force" : ""), timestampArtifactVersion);
@@ -111,4 +83,96 @@ private AppRegistration registerTimestampTask(String name, String timestampArtif
11183
registeredApps.add(registration);
11284
return registration;
11385
}
86+
87+
private AppRegistration registerTimeSource(String name, String timeSourceArtifactVersion, String bootVersionOption, boolean force) {
88+
String commandTemplate = "app register --type source --name %s %s %s --uri maven://org.springframework.cloud.stream.app:time-source-kafka:%s";
89+
String command = String.format(commandTemplate, name, bootVersionOption, (force ? "--force" : ""), timeSourceArtifactVersion);
90+
logger.info("COMMAND -> {}", command);
91+
Object result = this.commandRunner.executeCommand(command);
92+
logger.info("RESULT <- {}", result);
93+
assertThat(registry.appExist(name, ApplicationType.source, timeSourceArtifactVersion)).isTrue();
94+
AppRegistration registration = registry.find(name, ApplicationType.source, timeSourceArtifactVersion);
95+
registeredApps.add(registration);
96+
return registration;
97+
}
98+
99+
@Nested
100+
class AppRegisterTests {
101+
@Test
102+
void taskAppNoBootVersion() {
103+
AppRegistration registration = registerTimestampTask("timestamp", "3.2.0", "", false);
104+
assertThat(registration.getVersion()).isEqualTo("3.2.0");
105+
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.defaultVersion());
106+
}
107+
108+
@Test
109+
void taskAppBootVersion2() {
110+
AppRegistration registration = registerTimestampTask("timestamp2", "3.2.0", "--bootVersion 2", false);
111+
assertThat(registration.getVersion()).isEqualTo("3.2.0");
112+
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT2);
113+
}
114+
115+
@Test
116+
void taskAppBootVersion3() {
117+
AppRegistration registration = registerTimestampTask("timestamp3", "3.2.1", "--bootVersion 3", false);
118+
assertThat(registration.getVersion()).isEqualTo("3.2.1");
119+
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT3);
120+
}
121+
122+
@Test
123+
void taskAppBootVersion2updateTo3() {
124+
AppRegistration registration = registerTimestampTask("timestamp2to3", "3.2.0", "-b 2", false);
125+
assertThat(registration.getVersion()).isEqualTo("3.2.0");
126+
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT2);
127+
// The 'force=true' signals to udpate the existing 'timestamp2to3' app
128+
registration = registerTimestampTask("timestamp2to3", "3.2.1", "-b 3", true);
129+
assertThat(registration.getVersion()).isEqualTo("3.2.1");
130+
assertThat(registration.getBootVersion()).isEqualTo(AppBootSchemaVersion.BOOT3);
131+
}
132+
}
133+
134+
@Nested
135+
class AppInfoTests {
136+
137+
@Test
138+
void noBootVersion() {
139+
registerAppAndVerifyInfoCommand("time1", "", AppBootSchemaVersion.defaultVersion());
140+
}
141+
142+
@ParameterizedTest
143+
@ValueSource(booleans = { true, false })
144+
void bootVersion2(boolean useLongBootVersionCommandArg) {
145+
String bootVersionCommandArg = useLongBootVersionCommandArg ? "--bootVersion 2" : "-b 2";
146+
registerAppAndVerifyInfoCommand("time2", bootVersionCommandArg, AppBootSchemaVersion.BOOT2);
147+
}
148+
149+
@ParameterizedTest
150+
@ValueSource(booleans = { true, false })
151+
void bootVersion3(boolean useLongBootVersionCommandArg) {
152+
String bootVersionCommandArg = useLongBootVersionCommandArg ? "--bootVersion 3" : "-b 3";
153+
registerAppAndVerifyInfoCommand("time2", bootVersionCommandArg, AppBootSchemaVersion.BOOT3);
154+
}
155+
156+
private void registerAppAndVerifyInfoCommand(String appName, String bootVersionCommandArg, AppBootSchemaVersion expectedBootVersion) {
157+
AppRegistration registration = registerTimeSource(appName, "3.2.1", bootVersionCommandArg, false);
158+
assertThat(registration.getBootVersion()).isEqualTo(expectedBootVersion);
159+
TablesInfo info = invokeAppInfoCommand(appName, ApplicationType.source);
160+
assertResultHasBootVersion(info, expectedBootVersion);
161+
}
162+
163+
private TablesInfo invokeAppInfoCommand(String name, ApplicationType type) {
164+
String command = String.format( "app info --name %s --type %s ", name, type.name());
165+
logger.info("COMMAND -> {}", command);
166+
Object result = AppRegistryCommandsTests.this.commandRunner.executeCommand(command);
167+
logger.info("RESULT <- {}", result);
168+
assertThat(result).isInstanceOf(TablesInfo.class);
169+
return (TablesInfo) result;
170+
}
171+
172+
private void assertResultHasBootVersion(TablesInfo result, AppBootSchemaVersion expectedBootVersion) {
173+
assertThat(result)
174+
.extracting(TablesInfo::getHeaders).asList()
175+
.contains(String.format("Boot version: %s:", expectedBootVersion.getBootVersion()));
176+
}
177+
}
114178
}

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/ConfigCommandTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class ConfigCommandTests {
7777

7878
@Before
7979
public void setUp() {
80-
MockitoAnnotations.initMocks(this);
80+
MockitoAnnotations.openMocks(this);
8181

8282
dataFlowShell = new DataFlowShell();
8383

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/JobCommandTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
import javax.sql.DataSource;
2626

27-
import org.junit.AfterClass;
28-
import org.junit.BeforeClass;
29-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.BeforeAll;
29+
import org.junit.jupiter.api.Test;
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232

@@ -77,7 +77,7 @@ public class JobCommandTests extends AbstractShellIntegrationTest {
7777

7878
private static List<Long> taskExecutionIds = new ArrayList<>(3);
7979

80-
@BeforeClass
80+
@BeforeAll
8181
public static void setUp() throws Exception {
8282
Thread.sleep(2000);
8383
DataSource dataSource = applicationContext.getBean(DataSource.class);
@@ -93,7 +93,7 @@ public static void setUp() throws Exception {
9393
taskExecutionIds.add(createSampleJob(JOB_NAME_FOOBAR, 2));
9494
}
9595

96-
@AfterClass
96+
@AfterAll
9797
public static void tearDown() {
9898
if (applicationContext == null) {
9999
logger.warn("Application context was null (probably due to setup failure) - not performing tearDown");

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/RuntimeCommandsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class RuntimeCommandsTests {
6767

6868
@Before
6969
public void setUp() {
70-
MockitoAnnotations.initMocks(this);
70+
MockitoAnnotations.openMocks(this);
7171
when(dataFlowOperations.runtimeOperations()).thenReturn(runtimeOperations);
7272
DataFlowShell dataFlowShell = new DataFlowShell();
7373
dataFlowShell.setDataFlowOperations(dataFlowOperations);

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/StreamCommandTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.util.Arrays;
2020

21-
import org.junit.After;
22-
import org.junit.Before;
23-
import org.junit.Test;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424
import org.mockito.ArgumentMatchers;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
@@ -54,13 +54,13 @@ public class StreamCommandTests extends AbstractShellIntegrationTest {
5454

5555
private static final Logger logger = LoggerFactory.getLogger(StreamCommandTests.class);
5656

57-
@Before
57+
@BeforeEach
5858
public void registerApps() {
5959
AppRegistryService registry = applicationContext.getBean(AppRegistryService.class);
6060
registry.importAll(true, new ClassPathResource(APPS_URI));
6161
}
6262

63-
@After
63+
@AfterEach
6464
public void destroyStreams() {
6565
stream().destroyCreatedStreams();
6666
}

0 commit comments

Comments
 (0)