PendingActionCurator { @NotNull CurateResult curate(@NotNull ActionStore.PendingAction added, @NotNull ActionStore.PendingAction existing) { if (added.equals(existing)) { return KEEP_EXISTING_REMOVE_ADDED_STOP; } if (added.clientAction != null) { if (existing.clientAction != null) { if (added.sourceId.equals(existing.sourceId) && added.clientAction.getActionId().equals(existing.clientAction.getActionId())) { if (LOG.isDebugEnabled()) { LOG.debug("Skipping duplicate action " + added.clientAction); } return KEEP_EXISTING_REMOVE_ADDED_STOP; } return curateClientActions(added.clientAction, existing.clientAction); } if (existing.serverAction != null) { return curateClientServerActions(added.clientAction, existing.serverAction); } } if (added.serverAction != null) { if (existing.clientAction != null) { return curateServerClientActions(added.serverAction, existing.clientAction); } if (existing.serverAction != null) { if (added.sourceId.equals(existing.sourceId) && added.serverAction.getActionId().equals(existing.serverAction.getActionId())) { if (LOG.isDebugEnabled()) { LOG.debug("Skipping duplicate action " + added.serverAction); } return KEEP_EXISTING_REMOVE_ADDED_STOP; } return curateServerActions(added.serverAction, existing.serverAction); } } return KEEP_BOTH_CONTINUE; } PendingActionCurator(@NotNull PendingActionFactory actionFactory);   }
@Test void exact_equal_pending() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateChangelistAction action = new CreateChangelistAction(REF_A1, "comment", "local-id"); ActionStore.PendingAction pending = ActionStore.createPendingAction(REF_A1, action); PendingActionCurator.CurateResult res = curator.curate(pending, pending); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void exact_equal_client_action() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateChangelistAction action = new CreateChangelistAction(REF_A2, "comment", "local-id"); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A2, action); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A2, action); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void exact_equal_server_action() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateJobAction action = new CreateJobAction(new P4JobImpl("j1", "j1", null)); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A, action); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A, action); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void createJob_after_notCreateJob() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateJobAction addedAction = new CreateJobAction(new P4JobImpl("j1", "j1", null)); LoginAction existingAction = new LoginAction(); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A, existingAction); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A, addedAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_BOTH_CONTINUE, res); }
@Test void createJob1_after_createJob2() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateJobAction addedAction = new CreateJobAction(new P4JobImpl("j1", "j1", null)); CreateJobAction existingAction = new CreateJobAction(new P4JobImpl("j2", "j2", null)); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A, existingAction); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A, addedAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_BOTH_CONTINUE, res); }
@Test void createJob1_after_createJob1() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateJobAction addedAction = new CreateJobAction(new P4JobImpl("j1", "j1", null)); CreateJobAction existingAction = new CreateJobAction(new P4JobImpl("j1", "j1", null)); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A, existingAction); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A, addedAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void login() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); CreateJobAction existingAction = new CreateJobAction(new P4JobImpl("j1", "j1", null)); LoginAction addedAction = new LoginAction(); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_A, existingAction); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_A, addedAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void fetchFiles() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); FetchFilesAction addedAction = new FetchFilesAction(Collections.emptyList(), null, false); CreateChangelistAction existingAction = new CreateChangelistAction(REF_B2, "comment", "local-id"); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_B2, addedAction); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_B2, existingAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }
@Test void submitFiles() { PendingActionCurator.PendingActionFactory actionFactory = mock(PendingActionCurator.PendingActionFactory.class); PendingActionCurator curator = new PendingActionCurator(actionFactory); SubmitChangelistAction addedAction = new SubmitChangelistAction( new P4ChangelistIdImpl(100, REF_B1), Collections.emptyList(), null, null, null); CreateChangelistAction existingAction = new CreateChangelistAction(REF_B1, "comment", "local-id"); ActionStore.PendingAction added = ActionStore.createPendingAction(REF_B1, addedAction); ActionStore.PendingAction existing = ActionStore.createPendingAction(REF_B1, existingAction); PendingActionCurator.CurateResult res = curator.curate(added, existing); assertEquals(PendingActionCurator.KEEP_EXISTING_REMOVE_ADDED_STOP, res); }