@Test
 @Ignore("Cannot mock the log")
 public void canDoActionSucceedsWhenHasPeersThrowsException() throws Exception {
   setupGlusterMock(true, new VDS(), true);
   when(glusterUtil.getPeers(any(EngineSSHClient.class))).thenThrow(new RuntimeException());
   assertTrue(commandMock.canDoAction());
 }
  private void setupGlusterMock(boolean clusterHasServers, VDS upServer, boolean hasPeers)
      throws Exception {
    setupCommonMock(true);

    when(commandMock.createReturnValue()).thenCallRealMethod();
    when(commandMock.getReturnValue()).thenCallRealMethod();
    doCallRealMethod().when(commandMock).addCanDoActionMessage(any(EngineMessage.class));

    when(commandMock.getGlusterUtil()).thenReturn(glusterUtil);
    when(glusterUtil.getPeers(any(EngineSSHClient.class)))
        .thenReturn(hasPeers ? Collections.singleton(PEER_1) : Collections.<String>emptySet());

    when(commandMock.getGlusterDBUtils()).thenReturn(glusterDBUtils);

    when(clusterUtils.hasServers(any(Guid.class))).thenReturn(clusterHasServers);
    when(vdsDaoMock.getAllForVdsGroup(any(Guid.class)))
        .thenReturn(
            mockVdsInDb(clusterHasServers ? VDSStatus.Maintenance : VDSStatus.Initializing));
    when(clusterUtils.getUpServer(any(Guid.class))).thenReturn(upServer);

    // commandMock.log = log;
  }
Example #3
0
 protected GlusterUtil getGlusterUtil() {
   return GlusterUtil.getInstance();
 }