ViewConfigController extends BaseController { @RequestMapping(path = "/copy/{id}", method = RequestMethod.POST) @Transactional public String copyView(@PathVariable final Long id, final RedirectAttributes redirectAttributes) { if (!viewRepository.existsById(id)) { redirectAttributes.addFlashAttribute("FlashMessage", FlashMessage.newWarning("Unable to find view!")); } else { viewRepository.findById(id).ifPresent((view) -> { final ViewCopyManager copyManager = new ViewCopyManager(viewRepository); final String newName = "Copy of " + view.getName(); copyManager.copy(view, newName); redirectAttributes.addFlashAttribute( "FlashMessage", FlashMessage.newSuccess("Copied view using name '" + newName + "'!") ); }); } return "redirect:/configuration/view"; }  @RequestMapping(path = "", method = RequestMethod.GET) String datatable(
        final Model model,
        @RequestParam(name = "cluster.id", required = false) final Long clusterId,
        final Pageable pageable,
        @RequestParam Map<String,String> allParams
    ); @RequestMapping(path = "/create", method = RequestMethod.GET) String createViewForm(final ViewForm viewForm, final Model model, final RedirectAttributes redirectAttributes); @RequestMapping(path = "/edit/{id}", method = RequestMethod.GET) String editViewForm(
        @PathVariable final Long id,
        final ViewForm viewForm,
        final RedirectAttributes redirectAttributes,
        final Model model); @RequestMapping(path = "/update", method = RequestMethod.POST) String updateView(
        @Valid final ViewForm viewForm,
        final BindingResult bindingResult,
        final RedirectAttributes redirectAttributes,
        final Model model,
        @RequestParam final Map<String, String> allRequestParams); @RequestMapping(path = "/delete/{id}", method = RequestMethod.POST) String deleteView(@PathVariable final Long id, final RedirectAttributes redirectAttributes); @RequestMapping(path = "/copy/{id}", method = RequestMethod.POST) @Transactional String copyView(@PathVariable final Long id, final RedirectAttributes redirectAttributes);  }
@Test @Transactional public void testCopyView() throws Exception { final String originalViewName = "My Original View"; final String partitions = "1,2,4"; final String topic = "MyTopic"; final String expectedCopyName = "Copy of " + originalViewName; final Cluster cluster = clusterTestTools.createCluster("Test Cluster"); final MessageFormat keyMessageFormat = messageFormatTestTools.createMessageFormat("Key Message Format"); final MessageFormat valueMessageFormat = messageFormatTestTools.createMessageFormat("Value Message Format"); final View sourceView = viewTestTools.createView(originalViewName, cluster, keyMessageFormat); sourceView.setKeyMessageFormat(keyMessageFormat); sourceView.setValueMessageFormat(valueMessageFormat); sourceView.setTopic(topic); sourceView.setPartitions(partitions); viewRepository.save(sourceView); mockMvc .perform(post("/configuration/view/copy/" + sourceView.getId()) .with(csrf()) .with(user(adminUserDetails)) ) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("/configuration/view")); final View copiedView = viewRepository.findByName(expectedCopyName); assertNotNull(copiedView); Assert.assertNotNull("Should be non-null", copiedView); Assert.assertNotNull("Should have an id", copiedView.getId()); assertNotEquals("Should have a new id", copiedView.getId(), sourceView.getId()); assertEquals("Has new name", expectedCopyName, copiedView.getName()); assertEquals("Has topic", topic, copiedView.getTopic()); assertEquals("Has partitions", partitions, copiedView.getPartitions()); assertEquals("Has cluster", cluster.getId(), copiedView.getCluster().getId()); assertEquals("Has key format", keyMessageFormat.getId(), copiedView.getKeyMessageFormat().getId()); assertEquals("Has value format", valueMessageFormat.getId(), copiedView.getValueMessageFormat().getId()); }