2121 * questions.
2222 */
2323
24+ import static jdk .jpackage .test .JPackageStringBundle .MAIN ;
25+
2426import java .io .IOException ;
2527import java .nio .file .Path ;
26- import jdk .jpackage .test .TKit ;
28+ import java .util .List ;
29+ import java .util .Objects ;
30+ import jdk .jpackage .test .Annotations .Test ;
31+ import jdk .jpackage .test .JPackageCommand ;
32+ import jdk .jpackage .test .LinuxHelper ;
2733import jdk .jpackage .test .PackageTest ;
2834import jdk .jpackage .test .PackageType ;
29- import jdk .jpackage .test .LinuxHelper ;
30- import jdk .jpackage .test .Annotations .Test ;
31- import java .util .List ;
35+ import jdk .jpackage .test .RunnablePackageTest .Action ;
36+ import jdk .jpackage .test .TKit ;
3237
3338/*
3439 * @test
@@ -55,48 +60,47 @@ public static void testHardcodedProperties() throws IOException {
5560 })
5661 .forTypes (PackageType .LINUX_DEB )
5762 .addInitializer (cmd -> {
58- Path controlFile = Path .of (cmd .getArgumentValue ("--resource-dir" ),
59- "control" );
63+ Path controlFile = Path .of (cmd .getArgumentValue ("--resource-dir" ), "control" );
64+
65+ final var packageProp = property ("Package" , "dont-install-me" );
66+ final var verProp = property ("Version" , "1.2.3-R2" );
67+ final var arhProp = property ("Architecture" , "bar" );
68+
6069 TKit .createTextFile (controlFile , List .of (
61- "Package: dont-install-me" ,
62- "Version: 1.2.3-R2" ,
70+ packageProp . format () ,
71+ verProp . format () ,
6372 "Section: APPLICATION_SECTION" ,
6473 "Maintainer: APPLICATION_MAINTAINER" ,
6574 "Priority: optional" ,
66- "Architecture: bar" ,
75+ arhProp . format () ,
6776 "Provides: dont-install-me" ,
6877 "Description: APPLICATION_DESCRIPTION" ,
6978 "Installed-Size: APPLICATION_INSTALLED_SIZE" ,
7079 "Depends: PACKAGE_DEFAULT_DEPENDENCIES"
7180 ));
72- })
73- .addBundleVerifier ((cmd , result ) -> {
74- TKit .assertTextStream ("Using custom package resource [DEB control file]" )
75- .predicate (String ::contains )
76- .apply (result .getOutput ().stream ());
77- TKit .assertTextStream (String .format (
78- "Expected value of \" Package\" property is [%s]. Actual value in output package is [dont-install-me]" ,
79- LinuxHelper .getPackageName (cmd )))
80- .predicate (String ::contains )
81- .apply (result .getOutput ().stream ());
82- TKit .assertTextStream (
83- "Expected value of \" Version\" property is [1.0]. Actual value in output package is [1.2.3-R2]" )
84- .predicate (String ::contains )
85- .apply (result .getOutput ().stream ());
86- TKit .assertTextStream (String .format (
87- "Expected value of \" Architecture\" property is [%s]. Actual value in output package is [bar]" ,
88- LinuxHelper .getDefaultPackageArch (cmd .packageType ())))
89- .predicate (String ::contains )
90- .apply (result .getOutput ().stream ());
81+
82+ cmd .validateOutput (MAIN .cannedFormattedString (
83+ "message.using-custom-resource" ,
84+ String .format ("[%s]" , MAIN .cannedFormattedString ("resource.deb-control-file" ).getValue ()),
85+ controlFile .getFileName ()));
86+
87+ packageProp .expectedValue (LinuxHelper .getPackageName (cmd )).token ("APPLICATION_PACKAGE" ).resourceDirFile (controlFile ).validateOutput (cmd );
88+ verProp .expectedValue (cmd .version ()).token ("APPLICATION_VERSION_WITH_RELEASE" ).resourceDirFile (controlFile ).validateOutput (cmd );
89+ arhProp .expectedValue (LinuxHelper .getDefaultPackageArch (cmd .packageType ())).token ("APPLICATION_ARCH" ).resourceDirFile (controlFile ).validateOutput (cmd );
9190 })
9291 .forTypes (PackageType .LINUX_RPM )
9392 .addInitializer (cmd -> {
9493 Path specFile = Path .of (cmd .getArgumentValue ("--resource-dir" ),
9594 LinuxHelper .getPackageName (cmd ) + ".spec" );
95+
96+ final var packageProp = property ("Name" , "dont-install-me" );
97+ final var verProp = property ("Version" , "1.2.3" );
98+ final var releaseProp = property ("Release" , "R2" );
99+
96100 TKit .createTextFile (specFile , List .of (
97- "Name: dont-install-me" ,
98- "Version: 1.2.3" ,
99- "Release: R2" ,
101+ packageProp . format () ,
102+ verProp . format () ,
103+ releaseProp . format () ,
100104 "Summary: APPLICATION_SUMMARY" ,
101105 "License: APPLICATION_LICENSE_TYPE" ,
102106 "Prefix: %{dirname:APPLICATION_DIRECTORY}" ,
@@ -113,25 +117,77 @@ public static void testHardcodedProperties() throws IOException {
113117 "%files" ,
114118 "APPLICATION_DIRECTORY"
115119 ));
120+
121+ cmd .validateOutput (MAIN .cannedFormattedString (
122+ "message.using-custom-resource" ,
123+ String .format ("[%s]" , MAIN .cannedFormattedString ("resource.rpm-spec-file" ).getValue ()),
124+ specFile .getFileName ()));
125+
126+ packageProp .expectedValue (LinuxHelper .getPackageName (cmd )).token ("APPLICATION_PACKAGE" ).resourceDirFile (specFile ).validateOutput (cmd );
127+ verProp .expectedValue (cmd .version ()).token ("APPLICATION_VERSION" ).resourceDirFile (specFile ).validateOutput (cmd );
128+ releaseProp .expectedValue ("1" ).token ("APPLICATION_RELEASE" ).resourceDirFile (specFile ).validateOutput (cmd );
116129 })
117- .addBundleVerifier ((cmd , result ) -> {
118- TKit .assertTextStream ("Using custom package resource [RPM spec file]" )
119- .predicate (String ::contains )
120- .apply (result .getOutput ().stream ());
121- TKit .assertTextStream (String .format (
122- "Expected value of \" Name\" property is [%s]. Actual value in output package is [dont-install-me]" ,
123- LinuxHelper .getPackageName (cmd )))
124- .predicate (String ::contains )
125- .apply (result .getOutput ().stream ());
126- TKit .assertTextStream (
127- "Expected value of \" Version\" property is [1.0]. Actual value in output package is [1.2.3]" )
128- .predicate (String ::contains )
129- .apply (result .getOutput ().stream ());
130- TKit .assertTextStream (
131- "Expected value of \" Release\" property is [1]. Actual value in output package is [R2]" )
132- .predicate (String ::contains )
133- .apply (result .getOutput ().stream ());
134- })
135- .run ();
130+ .run (Action .CREATE );
131+ }
132+
133+ private final static class PropertyValidator {
134+
135+ PropertyValidator name (String v ) {
136+ name = v ;
137+ return this ;
138+ }
139+
140+ PropertyValidator customValue (String v ) {
141+ customValue = v ;
142+ return this ;
143+ }
144+
145+ PropertyValidator expectedValue (String v ) {
146+ expectedValue = v ;
147+ return this ;
148+ }
149+
150+ PropertyValidator token (String v ) {
151+ token = v ;
152+ return this ;
153+ }
154+
155+ PropertyValidator resourceDirFile (Path v ) {
156+ resourceDirFile = v ;
157+ return this ;
158+ }
159+
160+ String format () {
161+ Objects .requireNonNull (name );
162+ Objects .requireNonNull (customValue );
163+ return String .format ("%s: %s" , name , customValue );
164+ }
165+
166+ void validateOutput (JPackageCommand cmd ) {
167+ Objects .requireNonNull (name );
168+ Objects .requireNonNull (customValue );
169+ Objects .requireNonNull (expectedValue );
170+ Objects .requireNonNull (token );
171+ Objects .requireNonNull (resourceDirFile );
172+
173+ final var customResourcePath = customResourcePath ();
174+ cmd .validateOutput (
175+ MAIN .cannedFormattedString ("error.unexpected-package-property" , name , expectedValue , customValue , customResourcePath ),
176+ MAIN .cannedFormattedString ("error.unexpected-package-property.advice" , token , customValue , name , customResourcePath ));
177+ }
178+
179+ private Path customResourcePath () {
180+ return resourceDirFile .getFileName ();
181+ }
182+
183+ private String name ;
184+ private String customValue ;
185+ private String expectedValue ;
186+ private String token ;
187+ private Path resourceDirFile ;
188+ }
189+
190+ private static PropertyValidator property (String name , String customValue ) {
191+ return new PropertyValidator ().name (name ).customValue (customValue );
136192 }
137193}
0 commit comments