@@ -98,7 +98,25 @@ private static Stream<Arguments> testCalculateExistingAppsToBackup() {
9898 List .of ("app-1-live" , "app-1-idle" ), Collections .emptyList ()),
9999 // (7) Deployed mta does not have backup descriptor in db and won't be preserved
100100 Arguments .of (List .of (new TestApplication ("app-1" , "app-1" , "1" ), new TestApplication ("app-2" , "app-2" , "1" )),
101- Collections .emptyList (), "2" , false , Collections .emptyList (), Collections .emptyList ()));
101+ Collections .emptyList (), "2" , false , Collections .emptyList (), Collections .emptyList ()),
102+ // (8) Deployed mta contains applications with different versions and existing backup
103+ Arguments .of (List .of (new TestApplication ("app-1" , "app-1-live" , "2" ),
104+ new TestApplication ("app-1" , "app-1-idle" , "3" , ProductizationState .IDLE )),
105+ List .of (new TestApplication ("app-1" , "mta-backup-app-1" , "1" )), "3" , true , List .of ("app-1-live" ),
106+ List .of (ImmutableCloudApplication .builder ()
107+ .name ("app-1-live" )
108+ .v3Metadata (Metadata .builder ()
109+ .annotation (MtaMetadataAnnotations .MTA_VERSION ,
110+ "2" )
111+ .build ())
112+ .build ())),
113+ // (9) Missing deployed mta and existing backup
114+ Arguments .of (Collections .emptyList (), List .of (new TestApplication ("app-1" , "mta-backup-app-1" , "1" )), "2" , false ,
115+ Collections .emptyList (), Collections .emptyList ()),
116+ // (10) Deployed mta contains applications with missing versions and existing backup
117+ Arguments .of (List .of (new TestApplication ("app-1" , "app-1" , null )),
118+ List .of (new TestApplication ("app-1" , "mta-backup-app-1" , "1" )), "2" , false , Collections .emptyList (),
119+ Collections .emptyList ()));
102120 }
103121
104122 @ ParameterizedTest
@@ -113,7 +131,8 @@ void testCalculateExistingAppsToBackup(List<TestApplication> deployedApplication
113131
114132 ExistingAppsToBackupCalculator calculator = new ExistingAppsToBackupCalculator (deployedMta , backupMta , descriptorBackupService );
115133
116- List <CloudApplication > appsToUndeploy = getAppsToUndeploy (deployedMta .getApplications (), appNamesToUndeploy );
134+ List <CloudApplication > appsToUndeploy = getAppsToUndeploy (deployedMta == null ? Collections .emptyList ()
135+ : deployedMta .getApplications (), appNamesToUndeploy );
117136 List <CloudApplication > appsToBackup = calculator .calculateExistingAppsToBackup (context , appsToUndeploy ,
118137 mtaVersionOfCurrentDescriptor );
119138
@@ -191,10 +210,13 @@ private DeployedMta getDeployedMta(List<TestApplication> deployedApplications) {
191210 deployedMtaApplications .add (ImmutableDeployedMtaApplication .builder ()
192211 .moduleName (application .moduleName )
193212 .name (application .appName )
194- .v3Metadata (Metadata .builder ()
195- .annotation (MtaMetadataAnnotations .MTA_VERSION ,
196- application .mtaVersion )
197- .build ())
213+ .v3Metadata (application .mtaVersion != null ? Metadata .builder ()
214+ .annotation (MtaMetadataAnnotations .MTA_VERSION ,
215+ application .mtaVersion )
216+ .build ()
217+ : Metadata .builder ()
218+ .annotations (Collections .emptyMap ())
219+ .build ())
198220 .productizationState (application .productizationState )
199221 .build ());
200222 }
@@ -203,7 +225,10 @@ private DeployedMta getDeployedMta(List<TestApplication> deployedApplications) {
203225 .applications (deployedMtaApplications )
204226 .metadata (ImmutableMtaMetadata .builder ()
205227 .id (MTA_ID )
206- .version (mtaVersion != null ? Version .parseVersion (mtaVersion ) : null )
228+ .version (mtaVersion != null && deployedApplications .stream ()
229+ .allMatch (deployedApplication -> mtaVersion .equals (deployedApplication .mtaVersion ))
230+ ? Version .parseVersion (mtaVersion )
231+ : null )
207232 .build ())
208233
209234 .build ();
0 commit comments