Search in sources :

Example 11 with VerificationMode

use of org.mockito.verification.VerificationMode in project cdap-ingest by caskdata.

the class RestClientTest method testNotAllowedResponseCodeAnalysis.

@Test
public void testNotAllowedResponseCodeAnalysis() {
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
    when(response.getStatusLine()).thenReturn(statusLine);
    TestUtils.verifyResponse(HttpStatus.SC_METHOD_NOT_ALLOWED, response);
    verify(response, new VerificationMode() {

        @Override
        public void verify(VerificationData verificationData) {
            Assert.assertEquals(2, verificationData.getAllInvocations().size());
        }
    }).getStatusLine();
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) ProtocolVersion(org.apache.http.ProtocolVersion) VerificationMode(org.mockito.verification.VerificationMode) VerificationData(org.mockito.internal.verification.api.VerificationData) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 12 with VerificationMode

use of org.mockito.verification.VerificationMode in project cloudstack by apache.

the class StorageSystemDataMotionStrategyTest method validateAddSourcePoolToPoolsMapDestinationPoolIsNotNFS.

@Test
public void validateAddSourcePoolToPoolsMapDestinationPoolIsNotNFS() {
    List<StoragePoolType> storagePoolTypes = new LinkedList<>(Arrays.asList(StoragePoolType.values()));
    storagePoolTypes.remove(StoragePoolType.NetworkFilesystem);
    Mockito.doReturn(false).when(destinationStoragePoolVoMock).isManaged();
    storagePoolTypes.forEach(poolType -> {
        Mockito.doReturn(poolType).when(destinationStoragePoolVoMock).getPoolType();
        strategy.addSourcePoolToPoolsMap(mapStringStoragePoolTypeMock, sourceStoragePoolVoMock, destinationStoragePoolVoMock);
    });
    VerificationMode times = Mockito.times(storagePoolTypes.size());
    Mockito.verify(destinationStoragePoolVoMock, times).isManaged();
    Mockito.verify(destinationStoragePoolVoMock, times).getPoolType();
    Mockito.verifyNoMoreInteractions(mapStringStoragePoolTypeMock, sourceStoragePoolVoMock, destinationStoragePoolVoMock);
}
Also used : StoragePoolType(com.cloud.storage.Storage.StoragePoolType) LinkedList(java.util.LinkedList) VerificationMode(org.mockito.verification.VerificationMode) Test(org.junit.Test)

Example 13 with VerificationMode

use of org.mockito.verification.VerificationMode in project cloudstack by apache.

the class SnapshotManagerTest method validatePersistSnapshotPolicyLockAquiredUpdateSnapshotPolicy.

@Test
public void validatePersistSnapshotPolicyLockAquiredUpdateSnapshotPolicy() {
    PowerMockito.mockStatic(GlobalLock.class);
    BDDMockito.given(GlobalLock.getInternLock(Mockito.anyString())).willReturn(globalLockMock);
    Mockito.doReturn(true).when(globalLockMock).lock(Mockito.anyInt());
    for (IntervalType intervalType : listIntervalTypes) {
        Mockito.doReturn(snapshotPolicyVoInstance).when(snapshotPolicyDaoMock).findOneByVolumeInterval(Mockito.anyLong(), Mockito.eq(intervalType));
        Mockito.doNothing().when(_snapshotMgr).updateSnapshotPolicy(Mockito.any(SnapshotPolicyVO.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(DateUtil.IntervalType.class), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean());
        Mockito.doNothing().when(_snapshotMgr).createTagsForSnapshotPolicy(mapStringStringMock, snapshotPolicyVoMock);
        SnapshotPolicyVO result = _snapshotMgr.persistSnapshotPolicy(volumeMock, TEST_SNAPSHOT_POLICY_SCHEDULE, TEST_SNAPSHOT_POLICY_TIMEZONE, intervalType, TEST_SNAPSHOT_POLICY_MAX_SNAPS, TEST_SNAPSHOT_POLICY_DISPLAY, TEST_SNAPSHOT_POLICY_ACTIVE, null);
        assertSnapshotPolicyResultAgainstPreBuiltInstance(result);
    }
    VerificationMode timesVerification = Mockito.times(listIntervalTypes.size());
    Mockito.verify(_snapshotMgr, Mockito.never()).createSnapshotPolicy(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.any(DateUtil.IntervalType.class), Mockito.anyInt(), Mockito.anyBoolean());
    Mockito.verify(_snapshotMgr, timesVerification).updateSnapshotPolicy(Mockito.any(SnapshotPolicyVO.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(DateUtil.IntervalType.class), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean());
    Mockito.verify(_snapshotMgr, timesVerification).createTagsForSnapshotPolicy(Mockito.any(), Mockito.any());
}
Also used : IntervalType(com.cloud.utils.DateUtil.IntervalType) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO) VerificationMode(org.mockito.verification.VerificationMode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with VerificationMode

use of org.mockito.verification.VerificationMode in project cloudstack by apache.

the class SnapshotManagerTest method validatePersistSnapshotPolicyLockAquiredCreateSnapshotPolicy.

@Test
public void validatePersistSnapshotPolicyLockAquiredCreateSnapshotPolicy() {
    PowerMockito.mockStatic(GlobalLock.class);
    BDDMockito.given(GlobalLock.getInternLock(Mockito.anyString())).willReturn(globalLockMock);
    Mockito.doReturn(true).when(globalLockMock).lock(Mockito.anyInt());
    for (IntervalType intervalType : listIntervalTypes) {
        Mockito.doReturn(null).when(snapshotPolicyDaoMock).findOneByVolumeInterval(Mockito.anyLong(), Mockito.eq(intervalType));
        Mockito.doReturn(snapshotPolicyVoInstance).when(_snapshotMgr).createSnapshotPolicy(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.eq(intervalType), Mockito.anyInt(), Mockito.anyBoolean());
        Mockito.doNothing().when(_snapshotMgr).createTagsForSnapshotPolicy(mapStringStringMock, snapshotPolicyVoMock);
        SnapshotPolicyVO result = _snapshotMgr.persistSnapshotPolicy(volumeMock, TEST_SNAPSHOT_POLICY_SCHEDULE, TEST_SNAPSHOT_POLICY_TIMEZONE, intervalType, TEST_SNAPSHOT_POLICY_MAX_SNAPS, TEST_SNAPSHOT_POLICY_DISPLAY, TEST_SNAPSHOT_POLICY_ACTIVE, null);
        assertSnapshotPolicyResultAgainstPreBuiltInstance(result);
    }
    VerificationMode timesVerification = Mockito.times(listIntervalTypes.size());
    Mockito.verify(_snapshotMgr, timesVerification).createSnapshotPolicy(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.any(DateUtil.IntervalType.class), Mockito.anyInt(), Mockito.anyBoolean());
    Mockito.verify(_snapshotMgr, Mockito.never()).updateSnapshotPolicy(Mockito.any(SnapshotPolicyVO.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(DateUtil.IntervalType.class), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean());
    Mockito.verify(_snapshotMgr, timesVerification).createTagsForSnapshotPolicy(Mockito.any(), Mockito.any());
}
Also used : IntervalType(com.cloud.utils.DateUtil.IntervalType) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO) VerificationMode(org.mockito.verification.VerificationMode) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with VerificationMode

use of org.mockito.verification.VerificationMode in project kie-wb-common by kiegroup.

the class FormEditorPresenterTest method testOnRemoveComponent.

public void testOnRemoveComponent(boolean noContext) {
    loadContent();
    loadAvailableFields();
    addAllFields();
    VerificationMode count = times(1);
    if (noContext) {
        when(editorHelper.getContent()).thenReturn(null);
        count = never();
    }
    FormEditorPresenter presenterSpy = spy(presenter);
    String formId = presenterSpy.getFormDefinition().getId();
    FieldDefinition field = editorHelper.getFormDefinition().getFields().get(0);
    ComponentRemovedEvent event = new ComponentRemovedEvent(createLayoutComponent(presenter.getFormDefinition(), field), false);
    presenterSpy.onRemoveComponent(event);
    verify(presenterSpy, count).onSyncPalette(formId);
    verify(editorHelper, count).removeField(Mockito.<String>any(), Mockito.anyBoolean());
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) ComponentRemovedEvent(org.uberfire.ext.layout.editor.client.api.ComponentRemovedEvent) VerificationMode(org.mockito.verification.VerificationMode)

Aggregations

VerificationMode (org.mockito.verification.VerificationMode)31 Test (org.junit.Test)18 DummyVerificationMode (org.mockito.internal.verification.DummyVerificationMode)5 MockAwareVerificationMode (org.mockito.internal.verification.MockAwareVerificationMode)3 SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)2 IntervalType (com.cloud.utils.DateUtil.IntervalType)2 Method (java.lang.reflect.Method)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AcknowledgeCheckpoint (org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint)2 DeclineCheckpoint (org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)2 OperatorStreamStateHandle (org.apache.flink.runtime.state.OperatorStreamStateHandle)2 PlaceholderStreamStateHandle (org.apache.flink.runtime.state.PlaceholderStreamStateHandle)2 StateHandleID (org.apache.flink.runtime.state.StateHandleID)2 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)2 TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)2 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)2