@Test @Transactional public void basicCopyTest() { final String originalViewName = "My Original View"; final String partitions = "1,2,4"; final String topic = "MyTopic"; final String expectedCopyName = "My Copied View"; 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); final ViewCopyManager copyManager = new ViewCopyManager(viewRepository); final View copiedView = copyManager.copy(sourceView.getId(),expectedCopyName); assertNotNull("Should be non-null", copiedView); 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()); }
public View copy(final long sourceViewId, final String newViewName) { final Optional<View> sourceView = viewRepository.findById(sourceViewId); if (!sourceView.isPresent()) { throw new IllegalArgumentException("Unable to find view with id " + sourceViewId); } return copy(sourceView.get(), newViewName); }
ViewCopyManager { public View copy(final long sourceViewId, final String newViewName) { final Optional<View> sourceView = viewRepository.findById(sourceViewId); if (!sourceView.isPresent()) { throw new IllegalArgumentException("Unable to find view with id " + sourceViewId); } return copy(sourceView.get(), newViewName); } }
ViewCopyManager { public View copy(final long sourceViewId, final String newViewName) { final Optional<View> sourceView = viewRepository.findById(sourceViewId); if (!sourceView.isPresent()) { throw new IllegalArgumentException("Unable to find view with id " + sourceViewId); } return copy(sourceView.get(), newViewName); } @Autowired  ViewCopyManager(final ViewRepository viewRepository); }
ViewCopyManager { public View copy(final long sourceViewId, final String newViewName) { final Optional<View> sourceView = viewRepository.findById(sourceViewId); if (!sourceView.isPresent()) { throw new IllegalArgumentException("Unable to find view with id " + sourceViewId); } return copy(sourceView.get(), newViewName); } @Autowired  ViewCopyManager(final ViewRepository viewRepository); View copy(final long sourceViewId, final String newViewName); View copy(final View sourceView, final String newViewName); }
ViewCopyManager { public View copy(final long sourceViewId, final String newViewName) { final Optional<View> sourceView = viewRepository.findById(sourceViewId); if (!sourceView.isPresent()) { throw new IllegalArgumentException("Unable to find view with id " + sourceViewId); } return copy(sourceView.get(), newViewName); } @Autowired  ViewCopyManager(final ViewRepository viewRepository); View copy(final long sourceViewId, final String newViewName); View copy(final View sourceView, final String newViewName);  }