CurrentVariantRollbackService { public void rollbackCurrentVariantsFromTMToDate(DateTime rollbackDateTime, Long tmId) { rollbackCurrentVariantsFromTMToDate(rollbackDateTime, tmId, new CurrentVariantRollbackParameters()); }  void rollbackCurrentVariantsFromTMToDate(DateTime rollbackDateTime, Long tmId); @Transactional void rollbackCurrentVariantsFromTMToDate(DateTime rollbackDateTime, Long tmId, CurrentVariantRollbackParameters extraParameters);  }
@Test public void testRollbackShouldDeleteCurrentVariantsWhenTmTextUnitDidNotHaveAnyVariants() throws InterruptedException { TMTextUnit tmTextUnit = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnitId = tmTextUnit.getId(); DateTime dateTimeBeforeAddingVariant = new DateTime(); assertOnlyEnglishVariantIsPresent(tmTextUnitId); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), jaLocaleId, "こんにちは、世界!"); assertCurrentVariantWasSet("The added variants should be set as current", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnitId); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeAddingVariant, tm.getId()); assertNoCurrentVariantSet("After rollback, there should not be any current variants anymore", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnitId); }
@Test public void testRollbackShouldDeleteCurrentVariantsForGivenLocalesWhenTmTextUnitDidNotHaveAnyVariants() throws InterruptedException { TMTextUnit tmTextUnit = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnitId = tmTextUnit.getId(); DateTime dateTimeBeforeAddingVariant = new DateTime(); assertOnlyEnglishVariantIsPresent(tmTextUnitId); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), jaLocaleId, "こんにちは、世界!"); assertCurrentVariantWasSet("The added variants should be set as current", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnitId); CurrentVariantRollbackParameters rollbackParameters = new CurrentVariantRollbackParameters(); rollbackParameters.setLocaleIds(Arrays.asList(jaLocaleId)); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeAddingVariant, tm.getId(), rollbackParameters); assertCurrentVariantWasSet("After rollback, there should still be a current variant for fr-FR", Arrays.asList(frLocaleId), tmTextUnitId); assertNoCurrentVariantSet("After rollback, there should not be any current variant anymore for ja-JP", Arrays.asList(jaLocaleId), tmTextUnitId); }
@Test public void testRollbackShouldUndoChangesToCurrentVariantsWhenTmTextUnitHadVariants() throws InterruptedException { TMTextUnit tmTextUnit = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnitId = tmTextUnit.getId(); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), jaLocaleId, "こんにちは、世界!"); DateTime dateTimeBeforeChangingCurrentVariant = new DateTime(); assertVariantContentForCurrentVariantEquals("Bonjour le monde!", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("こんにちは、世界!", jaLocaleId, tmTextUnitId); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, frLocaleId, "Bonjour le monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, frLocaleId, "Bonjour le monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, jaLocaleId, "こんにちは、世界! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, jaLocaleId, "こんにちは、世界! 3"); assertVariantContentForCurrentVariantEquals("Bonjour le monde! 3", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("こんにちは、世界! 3", jaLocaleId, tmTextUnitId); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeChangingCurrentVariant, tm.getId()); assertVariantContentForCurrentVariantEquals("Bonjour le monde!", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("こんにちは、世界!", jaLocaleId, tmTextUnitId); }
@Test public void testRollbackShouldUndoChangesToCurrentVariantsForGivenLocalesWhenTmTextUnitHadVariants() throws InterruptedException { TMTextUnit tmTextUnit = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnitId = tmTextUnit.getId(); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit.getId(), jaLocaleId, "こんにちは、世界!"); DateTime dateTimeBeforeChangingCurrentVariant = new DateTime(); assertVariantContentForCurrentVariantEquals("Bonjour le monde!", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("こんにちは、世界!", jaLocaleId, tmTextUnitId); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, frLocaleId, "Bonjour le monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, frLocaleId, "Bonjour le monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, jaLocaleId, "こんにちは、世界! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnitId, jaLocaleId, "こんにちは、世界! 3"); assertVariantContentForCurrentVariantEquals("Bonjour le monde! 3", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("こんにちは、世界! 3", jaLocaleId, tmTextUnitId); CurrentVariantRollbackParameters rollbackParameters = new CurrentVariantRollbackParameters(); rollbackParameters.setLocaleIds(Arrays.asList(jaLocaleId)); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeChangingCurrentVariant, tm.getId(), rollbackParameters); assertVariantContentForCurrentVariantEquals("After rollback, the current variant should not have changed for fr-FR", "Bonjour le monde! 3", frLocaleId, tmTextUnitId); assertVariantContentForCurrentVariantEquals("After rollback, the current variant should have been rolled back for ja-JP", "こんにちは、世界!", jaLocaleId, tmTextUnitId); }
@Test public void testRollbackShouldDeleteCurrentVariantsForGivenTextUnitsWhenTmTextUnitDidNotHaveAnyVariants() throws InterruptedException { TMTextUnit tmTextUnit1 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnit1Id = tmTextUnit1.getId(); TMTextUnit tmTextUnit2 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_new_world", "Hello New World!", "Comments about hello new world"); Long tmTextUnit2Id = tmTextUnit2.getId(); assertOnlyEnglishVariantIsPresent(tmTextUnit1Id); assertOnlyEnglishVariantIsPresent(tmTextUnit2Id); DateTime dateTimeBeforeAddingVariant = new DateTime(); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), jaLocaleId, "こんにちは、世界!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), frLocaleId, "Bonjour le nouveau monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), jaLocaleId, "新しい世界をこんにちは!"); assertCurrentVariantWasSet("The added variants should be set as current", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnit1Id); assertCurrentVariantWasSet("The added variants should be set as current", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnit2Id); CurrentVariantRollbackParameters rollbackParameters = new CurrentVariantRollbackParameters(); rollbackParameters.setTmTextUnitIds(Arrays.asList(tmTextUnit1Id)); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeAddingVariant, tm.getId(), rollbackParameters); assertNoCurrentVariantSet("After rollback, the current variants of the text unit 1 should have been deleted", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnit1Id); assertCurrentVariantWasSet("After rollback, the current variants of the text unit 2 should still be there", Arrays.asList(frLocaleId, jaLocaleId), tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("Bonjour le nouveau monde!", frLocaleId, tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("新しい世界をこんにちは!", jaLocaleId, tmTextUnit2Id); }
@Test public void testRollbackShouldUndoChangesToCurrentVariantsForGivenTextUnitsWhenTmTextUnitHadVariants() throws InterruptedException { TMTextUnit tmTextUnit1 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnit1Id = tmTextUnit1.getId(); TMTextUnit tmTextUnit2 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_new_world", "Hello New World!", "Comments about hello new world"); Long tmTextUnit2Id = tmTextUnit2.getId(); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), jaLocaleId, "こんにちは、世界!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), frLocaleId, "Bonjour le nouveau monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), jaLocaleId, "新しい世界をこんにちは!"); assertVariantContentForCurrentVariantEquals("Bonjour le monde!", frLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("こんにちは、世界!", jaLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("Bonjour le nouveau monde!", frLocaleId, tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("新しい世界をこんにちは!", jaLocaleId, tmTextUnit2Id); DateTime dateTimeBeforeChangingCurrentVariant = new DateTime(); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, frLocaleId, "Bonjour le monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, frLocaleId, "Bonjour le monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, jaLocaleId, "こんにちは、世界! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, jaLocaleId, "こんにちは、世界! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, frLocaleId, "Bonjour le nouveau monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, frLocaleId, "Bonjour le nouveau monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, jaLocaleId, "新しい世界をこんにちは! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, jaLocaleId, "新しい世界をこんにちは! 3"); assertVariantContentForCurrentVariantEquals("Bonjour le monde! 3", frLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("こんにちは、世界! 3", jaLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("Bonjour le nouveau monde! 3", frLocaleId, tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("新しい世界をこんにちは! 3", jaLocaleId, tmTextUnit2Id); CurrentVariantRollbackParameters rollbackParameters = new CurrentVariantRollbackParameters(); rollbackParameters.setLocaleIds(Arrays.asList(jaLocaleId)); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeChangingCurrentVariant, tm.getId(), rollbackParameters); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 1 should not have changed for fr-FR", "Bonjour le monde! 3", frLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 2 should not have changed for fr-FR", "Bonjour le nouveau monde! 3", frLocaleId, tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 1 should have been rolled back for ja-JP", "こんにちは、世界!", jaLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 2 should have been rolled back for ja-JP", "新しい世界をこんにちは!", jaLocaleId, tmTextUnit2Id); }
@Test public void testRollbackShouldUndoChangesToCurrentVariantsForGivenLocalesAndTextUnitsWhenTmTextUnitHadVariants() throws InterruptedException { TMTextUnit tmTextUnit1 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_world", "Hello World!", "Comments about hello world"); Long tmTextUnit1Id = tmTextUnit1.getId(); TMTextUnit tmTextUnit2 = tmService.addTMTextUnit(tm.getId(), asset.getId(), "hello_new_world", "Hello New World!", "Comments about hello new world"); Long tmTextUnit2Id = tmTextUnit2.getId(); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), frLocaleId, "Bonjour le monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1.getId(), jaLocaleId, "こんにちは、世界!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), frLocaleId, "Bonjour le nouveau monde!"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2.getId(), jaLocaleId, "新しい世界をこんにちは!"); DateTime dateTimeBeforeChangingCurrentVariant = new DateTime(); Thread.sleep(10); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, frLocaleId, "Bonjour le monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, frLocaleId, "Bonjour le monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, jaLocaleId, "こんにちは、世界! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit1Id, jaLocaleId, "こんにちは、世界! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, frLocaleId, "Bonjour le nouveau monde! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, frLocaleId, "Bonjour le nouveau monde! 3"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, jaLocaleId, "新しい世界をこんにちは! 2"); tmService.addCurrentTMTextUnitVariant(tmTextUnit2Id, jaLocaleId, "新しい世界をこんにちは! 3"); CurrentVariantRollbackParameters rollbackParameters = new CurrentVariantRollbackParameters(); rollbackParameters.setLocaleIds(Arrays.asList(jaLocaleId)); rollbackParameters.setTmTextUnitIds(Arrays.asList(tmTextUnit2Id)); currentVariantRollbackService.rollbackCurrentVariantsFromTMToDate(dateTimeBeforeChangingCurrentVariant, tm.getId(), rollbackParameters); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 1 should not have changed for fr-FR", "Bonjour le monde! 3", frLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 2 should not have changed for fr-FR", "Bonjour le nouveau monde! 3", frLocaleId, tmTextUnit2Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 1 should not have changed for ja-JP", "こんにちは、世界! 3", jaLocaleId, tmTextUnit1Id); assertVariantContentForCurrentVariantEquals("After rollback, the current variant 2 should have been rolled back for ja-JP", "新しい世界をこんにちは!", jaLocaleId, tmTextUnit2Id); }