8209773: Refactor shell test javax/naming/module/basic.sh to java · openjdk/jdk11u-dev@95c94ae (original) (raw)

``

1

`+

/*

`

``

2

`+

`

``

3

`+

`

``

4

`+

`

``

5

`+

`

``

6

`+

`

``

7

`+

`

``

8

`+

`

``

9

`+

`

``

10

`+

`

``

11

`+

`

``

12

`+

`

``

13

`+

`

``

14

`+

`

``

15

`+

`

``

16

`+

`

``

17

`+

`

``

18

`+

`

``

19

`+

`

``

20

`+

`

``

21

`+

`

``

22

`+

*/

`

``

23

+

``

24

`+

import jdk.test.lib.JDKToolFinder;

`

``

25

`+

import jdk.test.lib.Utils;

`

``

26

`+

import jdk.test.lib.compiler.CompilerUtils;

`

``

27

`+

import jdk.test.lib.process.ProcessTools;

`

``

28

+

``

29

`+

import java.io.IOException;

`

``

30

`+

import java.nio.file.Files;

`

``

31

`+

import java.nio.file.Path;

`

``

32

`+

import java.util.Collection;

`

``

33

`+

import java.util.Collections;

`

``

34

`+

import java.util.List;

`

``

35

`+

import java.util.stream.Collectors;

`

``

36

`+

import java.util.stream.Stream;

`

``

37

+

``

38

`+

import static jdk.test.lib.Utils.TEST_SRC;

`

``

39

+

``

40

`+

/*

`

``

41

`+

`

``

42

`+

`

``

43

`+

`

``

44

`+

`

``

45

`+

`

``

46

`+

*/

`

``

47

+

``

48

`+

/*

`

``

49

`+

`

``

50

`+

`

``

51

`+

`

``

52

`+

`

``

53

`+

`

``

54

`+

`

``

55

`+

`

``

56

`+

`

``

57

`+

`

``

58

`+

`

``

59

`+

`

``

60

`+

`

``

61

`+

`

``

62

`+

*/

`

``

63

+

``

64

`+

public class RunBasic {

`

``

65

+

``

66

`+

private static final List JAVA_CMDS;

`

``

67

+

``

68

`+

static {

`

``

69

`+

String javaPath = JDKToolFinder.getJDKTool("java");

`

``

70

+

``

71

`+

JAVA_CMDS = Stream

`

``

72

`+

.concat(Stream.of(javaPath), Stream.of(Utils.getTestJavaOpts()))

`

``

73

`+

.collect(Collectors.collectingAndThen(Collectors.toList(),

`

``

74

`+

Collections::unmodifiableList));

`

``

75

`+

}

`

``

76

+

``

77

`+

public static void main(String[] args) throws Throwable {

`

``

78

`+

// prepare all test modules

`

``

79

`+

prepareModule("person");

`

``

80

`+

prepareModule("fruit");

`

``

81

`+

prepareModule("hello");

`

``

82

`+

prepareModule("foo");

`

``

83

`+

prepareModule("authz");

`

``

84

`+

prepareModule("ldapv4");

`

``

85

`+

prepareModule("test", "--module-source-path",

`

``

86

`+

Path.of(TEST_SRC, "src").toString());

`

``

87

+

``

88

`+

// run tests

`

``

89

`+

runTest("java.desktop", "test.StoreObject");

`

``

90

`+

runTest("person", "test.StorePerson");

`

``

91

`+

runTest("fruit", "test.StoreFruit");

`

``

92

`+

runTest("hello", "test.StoreRemote");

`

``

93

`+

runTest("foo", "test.ConnectWithFoo");

`

``

94

`+

runTest("authz", "test.ConnectWithAuthzId");

`

``

95

`+

runTest("ldapv4", "test.ReadByUrl");

`

``

96

`+

}

`

``

97

+

``

98

`+

private static void prepareModule(String mod, String... opts)

`

``

99

`+

throws IOException {

`

``

100

`+

System.out.println("Preparing the '" + mod + "' module...");

`

``

101

`+

makeDir("mods", mod);

`

``

102

`+

CompilerUtils.compile(Path.of(TEST_SRC, "src", mod),

`

``

103

`+

Path.of("mods", (mod.equals("test") ? "" : mod)), opts);

`

``

104

`+

}

`

``

105

+

``

106

`+

private static void makeDir(String first, String... more)

`

``

107

`+

throws IOException {

`

``

108

`+

Files.createDirectories(Path.of(first, more));

`

``

109

`+

}

`

``

110

+

``

111

`+

private static void runTest(String desc, String clsName) throws Throwable {

`

``

112

`+

System.out.println("Running with the '" + desc + "' module...");

`

``

113

`+

runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,

`

``

114

`+

"ldap://localhost/dc=ie,dc=oracle,dc=com");

`

``

115

`+

}

`

``

116

+

``

117

`+

private static void runJava(String... opts) throws Throwable {

`

``

118

`+

ProcessTools.executeCommand(

`

``

119

`+

Stream.of(JAVA_CMDS, List.of(opts)).flatMap(Collection::stream)

`

``

120

`+

.toArray(String[]::new)).shouldHaveExitValue(0);

`

``

121

`+

}

`

``

122

`+

}

`