Package org.zanata.webtrans.shared.model

Examples of org.zanata.webtrans.shared.model.TransUnit


        HasTransUnitUpdatedData updatedData =
                mock(HasTransUnitUpdatedData.class, withSettings()
                        .defaultAnswer(RETURNS_DEEP_STUBS));
        when(updatedData.getUpdateInfo().getDocumentId()).thenReturn(
                initContext.getDocument().getId());
        TransUnit updatedTU = data.get(0);
        when(updatedData.getUpdateInfo().getTransUnit()).thenReturn(updatedTU);
        EditorClientId editorClientId = new EditorClientId("sessionId", 1);
        when(updatedData.getEditorClientId()).thenReturn(editorClientId);
        when(updatedData.getUpdateType()).thenReturn(
                TransUnitUpdated.UpdateType.WebEditorSave);
View Full Code Here


                        .defaultAnswer(RETURNS_DEEP_STUBS));
        when(updatedData.getUpdateInfo().getDocumentId()).thenReturn(
                initContext.getDocument().getId());
        // updated TU has something different so that we can assert it won't
        // update current page data model
        TransUnit updatedTU =
                TransUnit.Builder.from(data.get(data.size() - 1))
                        .setSourceComment("different").build();
        when(updatedData.getUpdateInfo().getTransUnit()).thenReturn(updatedTU);

        // When:
        service.onTransUnitUpdated(new TransUnitUpdatedEvent(updatedData));

        // Then:
        verifyZeroInteractions(pageDataChangeListener);
        assertThat(data.get(data.size() - 1).getSourceComment(),
                Matchers.not(Matchers.equalTo(updatedTU.getSourceComment())));

    }
View Full Code Here

    public void onTransUnitEditEvent() {
        // Given:
        EditorClientId editorClientId = editorClientId();
        UserPanelSessionItem sessionItem =
                new UserPanelSessionItem(panel, TestFixture.person());
        TransUnit transUnit = TestFixture.makeTransUnit(2);
        service.getUserSessionMap().put(editorClientId, sessionItem);
        when(hasTransUnitData.getEditorClientId()).thenReturn(editorClientId);
        when(hasTransUnitData.getSelectedTransUnitId()).thenReturn(
                transUnit.getId());

        // When:
        service.onTransUnitEdit(new TransUnitEditEvent(hasTransUnitData));

        // Then:
        assertThat(service.getUserSessionMap().get(editorClientId)
                .getSelectedId(), Matchers.sameInstance(transUnit.getId()));
        assertThat(service.getUserSessionMap().get(editorClientId)
                .getSelectedId(), Matchers.sameInstance(transUnit.getId()));
    }
View Full Code Here

        Person person = TestFixture.person();
        when(event.getEditorClientId()).thenReturn(editorClientId);
        when(event.getPerson()).thenReturn(person);
        UserPanelSessionItem sessionItem =
                new UserPanelSessionItem(panel, person);
        TransUnit selectedTransUnit = TestFixture.makeTransUnit(1);
        sessionItem.setSelectedId(selectedTransUnit.getId());
        service.getUserSessionMap().put(editorClientId, sessionItem);

        service.onExitWorkspace(event);

        verify(workspaceUsersPresenter).removeUser(panel,
                person.getId().toString());
        verify(translatorInteractionService).personExit(person,
                selectedTransUnit.getId());
        assertThat(service.getUserSessionMap().size(), Matchers.is(0));
    }
View Full Code Here

    }

    @Test
    public void onSaveDoNothingIfStateHasNotChanged() {
        // Given: old state and content are equal to saving state and content
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.Approved, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When:
View Full Code Here

    }

    @Test
    public void willSaveIfSomethingHasChanged() {
        // Given:
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When: save as approved
View Full Code Here

    }

    @Test
    public void willSaveToQueueIfItsSavingSameRow() {
        // Given:
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When: save twice
View Full Code Here

    }

    @Test
    public void onRPCSuccessAndSaveReturnSuccess() {
        // Given:
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When: save as fuzzy
        service.onTransUnitSave(event("new content", ContentState.NeedReview,
                TRANS_UNIT_ID, VER_NUM, "old content"));

        // Then:
        verify(dispatcher).execute(actionCaptor.capture(),
                resultCaptor.capture());
        assertThat(actionCaptor.getValue().getUpdateType(),
                equalTo(TransUnitUpdated.UpdateType.WebEditorSave));

        // on save success
        // Given: result comes back with saving successful
        int rowIndex = 1;
        when(messages.notifyUpdateSaved(rowIndex, TRANS_UNIT_ID.toString()))
                .thenReturn("saved row 1, id 1");
        when(navigationService.findRowIndexById(TRANS_UNIT_ID)).thenReturn(
                rowIndex);
        when(undoProvider.get()).thenReturn(undoLink);

        AsyncCallback<UpdateTransUnitResult> callback = resultCaptor.getValue();
        TransUnit updatedTU =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "new content");
        UpdateTransUnitResult result =
                result(true, updatedTU, ContentState.NeedReview, null);
View Full Code Here

    }

    @Test
    public void onRPCSuccessAndThereIsPendingSave() {
        // Given:
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When: save twice and one will be pending
        service.onTransUnitSave(event("new content", ContentState.NeedReview,
                TRANS_UNIT_ID, VER_NUM, "old content"));
        service.onTransUnitSave(event("newer content", ContentState.NeedReview,
                TRANS_UNIT_ID, VER_NUM, "new content"));

        // Then: dispatcher will be call twice
        verify(dispatcher).execute(actionCaptor.capture(),
                resultCaptor.capture());

        // on save success
        // Given: result comes back with saving successful
        int rowIndex = 1;
        when(messages.notifyUpdateSaved(rowIndex, TRANS_UNIT_ID.toString()))
                .thenReturn("saved row 1, id 1");
        when(navigationService.findRowIndexById(TRANS_UNIT_ID)).thenReturn(
                rowIndex);
        when(undoProvider.get()).thenReturn(undoLink);

        AsyncCallback<UpdateTransUnitResult> callback = resultCaptor.getValue();
        TransUnit updatedTU =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "new content");
        UpdateTransUnitResult result =
                result(true, updatedTU, ContentState.NeedReview, null);
View Full Code Here

    @Test
    public void onPRCSuccessButSaveUnsuccessfulInResult() {
        // Given:
        String errorMessage = "unsuccessful save";
        TransUnit old =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "old content");
        when(navigationService.getByIdOrNull(TRANS_UNIT_ID)).thenReturn(old);

        // When: save as fuzzy
        service.onTransUnitSave(event("new content", ContentState.NeedReview,
                TRANS_UNIT_ID, VER_NUM, "old content"));

        // Then:
        verify(dispatcher).execute(actionCaptor.capture(),
                resultCaptor.capture());

        // on save success
        // Given: result comes back but saving operation failed
        when(messages.notifyUpdateFailed("id " + TRANS_UNIT_ID, errorMessage))
                .thenReturn("update failed");

        AsyncCallback<UpdateTransUnitResult> callback = resultCaptor.getValue();
        TransUnit updatedTU =
                TestFixture.makeTransUnit(TRANS_UNIT_ID.getId(),
                        ContentState.NeedReview, "new content");
        UpdateTransUnitResult result =
                result(false, updatedTU, ContentState.NeedReview, errorMessage);
View Full Code Here

TOP

Related Classes of org.zanata.webtrans.shared.model.TransUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.