Package com.sequenceiq.cloudbreak.service.cluster

Source Code of com.sequenceiq.cloudbreak.service.cluster.ClusterCreationFailureHandlerTest

package com.sequenceiq.cloudbreak.service.cluster;

import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import com.sequenceiq.cloudbreak.domain.Cluster;
import com.sequenceiq.cloudbreak.domain.WebsocketEndPoint;
import com.sequenceiq.cloudbreak.repository.ClusterRepository;
import com.sequenceiq.cloudbreak.service.cluster.event.ClusterCreationFailure;
import com.sequenceiq.cloudbreak.service.cluster.handler.ClusterCreationFailureHandler;
import com.sequenceiq.cloudbreak.websocket.WebsocketService;
import com.sequenceiq.cloudbreak.websocket.message.StatusMessage;

import reactor.event.Event;

public class ClusterCreationFailureHandlerTest {

    @InjectMocks
    private ClusterCreationFailureHandler underTest;

    @Mock
    private WebsocketService websocketService;

    @Mock
    private ClusterRepository clusterRepository;

    private ClusterCreationFailure clusterCreationFailure;

    private Event<ClusterCreationFailure> event;

    private Cluster cluster;

    @Before
    public void setUp() {
        underTest = new ClusterCreationFailureHandler();
        MockitoAnnotations.initMocks(this);
        clusterCreationFailure = new ClusterCreationFailure(1L, "dummyMessage");
        event = new Event<>(clusterCreationFailure);
        cluster = new Cluster();
        cluster.setEmailNeeded(false);
        cluster.setOwner("dummy@myemail.com");
        cluster.setAccount("myaccount");
    }

    @Test
    public void testAccept() {
        //GIVEN
        given(clusterRepository.findById(1L)).willReturn(cluster);
        doNothing().when(websocketService).sendToTopicUser(anyString(), any(WebsocketEndPoint.class), any(StatusMessage.class));
        //WHEN
        underTest.accept(event);
        //THEN
        verify(websocketService, times(1)).sendToTopicUser(anyString(), any(WebsocketEndPoint.class), any(StatusMessage.class));
    }
}
TOP

Related Classes of com.sequenceiq.cloudbreak.service.cluster.ClusterCreationFailureHandlerTest

TOP
Copyright © 2018 www.massapi.com. 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.