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

    final MessageFormat messageFormat = messageFormatTestTools.createMessageFormat("MyMessageFormat" + System.currentTimeMillis());
    final String expectedName = messageFormat.getName();
    final String expectedClasspath = messageFormat.getClasspath();
    final String expectedJarName = messageFormat.getJar();
    final String expectedJarContents = "OriginalContents";
    final String expectedParametersJson = messageFormat.getOptionParameters();
    final Path expectedJarPath = Paths.get(deserializerUploadPath, messageFormat.getJar());
    // Create a dummy jar
    FileTestTools.createDummyFile(deserializerUploadPath + messageFormat.getJar(), expectedJarContents);
    // This is an invalid jar.
    final MockMultipartFile jarUpload =
        new MockMultipartFile("file", "testPlugins.jar", null, "MyContent".getBytes(Charsets.UTF_8));
    // Hit page.
    mockMvc
        .perform(multipart("/configuration/messageFormat/update")
            .file(jarUpload)
            .with(user(adminUserDetails))
            .with(csrf())
            .param("id", String.valueOf(messageFormat.getId()))
            .param("name", "Updated Name")
            .param("classpath", "made.up.classpath")
            .param("customOptionNames", "option1")
            .param("customOptionNames", "option2")
            .param("customOptionValues", "value1")
            .param("customOptionValues", "value2"))
        //.andDo(print())
        .andExpect(model().hasErrors())
        .andExpect(model().attributeHasFieldErrors("messageFormatForm", "file"))
        .andExpect(status().isOk());
    // Validate message format was not updated.
    final MessageFormat updatedMessageFormat = messageFormatRepository.findById(messageFormat.getId()).get();
    assertNotNull("Has message format", updatedMessageFormat);
    assertEquals("Name not updated", expectedName, updatedMessageFormat.getName());
    assertEquals("classpath not updated", expectedClasspath, updatedMessageFormat.getClasspath());
    assertEquals("Jar name not updated", expectedJarName, updatedMessageFormat.getJar());
    assertFalse("Should not be a default format", updatedMessageFormat.isDefaultFormat());
    assertEquals("Parameters not updated", expectedParametersJson, updatedMessageFormat.getOptionParameters());
    // Validate previous jar not overwritten.
    assertTrue("File should exist", Files.exists(expectedJarPath));
    final String jarContents = FileTestTools.readFile(expectedJarPath.toString());
    assertEquals("Jar contents should not have changed", expectedJarContents, jarContents);
    // Cleanup
    Files.deleteIfExists(expectedJarPath);
}