2020package io .wcm .devops .conga .plugins .aem .maven .allpackage ;
2121
2222import static io .wcm .devops .conga .plugins .aem .maven .allpackage .ContentPackageTestUtil .assertXpathEvaluatesTo ;
23+ import static io .wcm .devops .conga .plugins .aem .maven .allpackage .ContentPackageTestUtil .getDataFromZip ;
2324import static io .wcm .devops .conga .plugins .aem .maven .allpackage .ContentPackageTestUtil .getXmlFromZip ;
2425import static org .junit .jupiter .api .Assertions .assertEquals ;
2526import static org .junit .jupiter .api .Assertions .assertTrue ;
2627
28+ import java .io .ByteArrayInputStream ;
2729import java .io .File ;
30+ import java .io .FileOutputStream ;
2831import java .io .IOException ;
2932import java .util .List ;
3033import java .util .Set ;
3134import java .util .stream .Stream ;
3235
3336import org .apache .commons .io .FileUtils ;
37+ import org .apache .commons .io .IOUtils ;
3438import org .apache .commons .lang3 .StringUtils ;
3539import org .junit .jupiter .api .BeforeEach ;
3640import org .junit .jupiter .api .TestInfo ;
@@ -131,6 +135,11 @@ void testBuild(Set<String> cloudManagerTarget, List<String> runmodeSuffixes) thr
131135 assertFiles (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
132136 "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip" ,
133137 "wcm-io-samples-complete" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip" );
138+ assertNameDependencies (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
139+ "accesscontroltool-package" + runmodeSuffix );
140+ assertNameDependenciesSubPackage (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
141+ "jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip" ,
142+ "accesscontroltool-apps-package" + runmodeSuffix );
134143 assertNameDependencies (containerInstallDir , "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip" ,
135144 "wcm-io-samples-aem-cms-config" + runmodeSuffix );
136145 assertNameDependencies (containerInstallDir , "wcm-io-samples-complete" + runmodeSuffix + "-1.3.1-SNAPSHOT.zip" ,
@@ -205,6 +214,10 @@ void testBuild_IMMUTABLE_MUTABLE_COMBINED(Set<String> cloudManagerTarget, List<S
205214 assertNameDependencies (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
206215 "accesscontroltool-package" + runmodeSuffix ,
207216 "adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0" );
217+ assertNameDependenciesSubPackage (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
218+ "jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip" ,
219+ "accesscontroltool-apps-package" + runmodeSuffix ,
220+ "adobe/consulting:acs-aem-commons-ui.content" + runmodeSuffix + ":4.10.0" );
208221 assertNameDependencies (containerInstallDir , "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip" ,
209222 "wcm-io-samples-aem-cms-config" + runmodeSuffix ,
210223 "wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT" );
@@ -280,6 +293,10 @@ void testBuild_IMMUTABLE_MUTABLE_SEPARATE(Set<String> cloudManagerTarget, List<S
280293 assertNameDependencies (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
281294 "accesscontroltool-package" + runmodeSuffix ,
282295 "adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0" );
296+ assertNameDependenciesSubPackage (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
297+ "jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip" ,
298+ "accesscontroltool-apps-package" + runmodeSuffix ,
299+ "adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0" );
283300 assertNameDependencies (containerInstallDir , "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip" ,
284301 "wcm-io-samples-aem-cms-config" + runmodeSuffix ,
285302 "wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT" );
@@ -353,6 +370,10 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
353370 assertNameDependencies (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
354371 "accesscontroltool-package" + runmodeSuffix ,
355372 "adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0" );
373+ assertNameDependenciesSubPackage (containerInstallDir , "accesscontroltool-package" + runmodeSuffix + "-3.0.0.zip" ,
374+ "jcr_root/apps/netcentric/actool/install/accesscontroltool-apps-package-3.0.0.zip" ,
375+ "accesscontroltool-apps-package" + runmodeSuffix ,
376+ "adobe/consulting:acs-aem-commons-ui.apps" + runmodeSuffix + ":4.10.0" );
356377 assertNameDependencies (containerInstallDir , "wcm-io-samples-aem-cms-config" + runmodeSuffix + ".zip" ,
357378 "wcm-io-samples-aem-cms-config" + runmodeSuffix ,
358379 "wcm-io-samples:aem-cms-system-config" + runmodeSuffix + ":1.3.1-SNAPSHOT" );
@@ -362,6 +383,11 @@ void testBuild_IMMUTABLE_ONLY(Set<String> cloudManagerTarget, List<String> runmo
362383 }
363384 }
364385
386+ /**
387+ * Assert existence of given files.
388+ * @param dir Directory
389+ * @param fileNames Expected file names in directory
390+ */
365391 private void assertFiles (File dir , String ... fileNames ) {
366392 assertTrue (dir .exists (), "file exists: " + dir .getPath ());
367393 assertTrue (dir .isDirectory (), "is directory: " + dir .getPath ());
@@ -371,6 +397,14 @@ private void assertFiles(File dir, String... fileNames) {
371397 assertEquals (expectedFileNames , actualFileNames , "files in " + dir .getPath ());
372398 }
373399
400+ /**
401+ * Assert content package name and list of package dependencies.
402+ * @param dir Directory
403+ * @param fileName Content package file name
404+ * @param packageName Expected content package name
405+ * @param dependencies Expected dependencies
406+ * @throws Exception Exception
407+ */
374408 private void assertNameDependencies (File dir , String fileName , String packageName ,
375409 String ... dependencies ) throws Exception {
376410 File zipFile = new File (dir , fileName );
@@ -385,6 +419,33 @@ private void assertNameDependencies(File dir, String fileName, String packageNam
385419 assertXpathEvaluatesTo (expecedDependencies , "/properties/entry[@key='dependencies']" , filterXml );
386420 }
387421
422+ /**
423+ * Assert content package name and list of package dependencies.
424+ * @param dir Directory
425+ * @param fileName Content package file name
426+ * @param subPackageFileName Path and file name of sub package inside main package.
427+ * @param packageName Expected content package name
428+ * @param dependencies Expected dependencies
429+ * @throws Exception Exception
430+ */
431+ private void assertNameDependenciesSubPackage (File dir , String fileName , String subPackageFileName ,
432+ String packageName , String ... dependencies ) throws Exception {
433+ File zipFile = new File (dir , fileName );
434+ byte [] subPackageData = getDataFromZip (zipFile , subPackageFileName );
435+ File tempPackageFile = File .createTempFile ("testpkg" , ".zip" );
436+ try (ByteArrayInputStream is = new ByteArrayInputStream (subPackageData );
437+ FileOutputStream fos = new FileOutputStream (tempPackageFile )) {
438+ IOUtils .copy (is , fos );
439+ }
440+ try {
441+ assertNameDependencies (tempPackageFile .getParentFile (), tempPackageFile .getName (),
442+ packageName , dependencies );
443+ }
444+ finally {
445+ FileUtils .deleteQuietly (tempPackageFile );
446+ }
447+ }
448+
388449 private String [] toInstallFolderNames (String baseName , List <String > runmodeSuffixes ) {
389450 return runmodeSuffixes .stream ()
390451 .map (suffix -> baseName + suffix )
0 commit comments