@Test
@Transactional
public void testPostUpdate_updatingExistingWithValidJarSameName() throws Exception {

    final MessageFormat messageFormat = messageFormatTestTools.createMessageFormat("MyMessageFormat" + System.currentTimeMillis());
    final String originalJarName = messageFormat.getJar();
    final String originalJarContents = "OriginalContents";
    final Path originalJarPath = Paths.get(deserializerUploadPath, messageFormat.getJar());
    // Create a dummy jar
    FileTestTools.createDummyFile(deserializerUploadPath + messageFormat.getJar(), originalJarContents);
    // This is a valid jar
    final InputStream fileInputStream = getClass().getClassLoader().getResourceAsStream("testDeserializer/testPlugins.jar");
    final MockMultipartFile jarUpload = new MockMultipartFile("file", "testPlugins.jar", null, fileInputStream);
    final String newName = "MyUpdatedName" + System.currentTimeMillis();
    final String newClasspath = "examples.deserializer.ExampleDeserializer";
    // Hit page.
    mockMvc
        .perform(multipart("/configuration/messageFormat/update")
            .file(jarUpload)
            .with(user(adminUserDetails))
            .with(csrf())
            .param("id", String.valueOf(messageFormat.getId()))
            .param("name", newName)
            .param("classpath", newClasspath))
        //.andDo(print())
        .andExpect(model().hasNoErrors())
        .andExpect(status().is3xxRedirection())
        .andExpect(redirectedUrl("/configuration/messageFormat"));
    // Validate message format was updated.
    final MessageFormat updatedMessageFormat = messageFormatRepository.findById(messageFormat.getId()).get();
    assertNotNull("Has message format", updatedMessageFormat);
    assertEquals("Name updated", newName, updatedMessageFormat.getName());
    assertEquals("classpath updated", newClasspath, updatedMessageFormat.getClasspath());
    assertNotEquals("Jar name not updated", originalJarName, updatedMessageFormat.getJar());
    assertFalse("Should not be a default format", updatedMessageFormat.isDefaultFormat());
    // No parameters were posted, so we should have an empty json parameters
    assertEquals("No parameters should be empty", "{}", updatedMessageFormat.getOptionParameters());
    // Validate previous jar is gone/deleted.
    assertFalse("File should NOT exist", Files.exists(originalJarPath));
    // Validate new jar is created.
    final Path newJarPath = Paths.get(deserializerUploadPath, updatedMessageFormat.getJar());
    assertTrue("New jar should exist", Files.exists(newJarPath));
    // Cleanup
    Files.deleteIfExists(newJarPath);
}