cloudstack/server/test/com/cloud/event/EventControlsUnitTest.java
Sanjay Tripathi f539f40e35 CLOUDSTACK-874: Ability to delete Events and Alerts
This feature will provide the functionality to delete or archive
the Alerts/Events.
Delete or archive alerts APIs are available only for root-admin,
delete or archive events are available for regular users.
2013-03-08 11:59:53 -08:00

69 lines
2.1 KiB
Java

package com.cloud.event;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyList;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import com.cloud.event.dao.EventDao;
import com.cloud.server.ManagementServerImpl;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
public class EventControlsUnitTest extends TestCase{
private static final Logger s_logger = Logger.getLogger(EventControlsUnitTest.class);
@Spy ManagementServerImpl _mgmtServer = new ManagementServerImpl();
@Mock AccountManager _accountMgr;
@Mock EventDao _eventDao;
List<EventVO> _events = null;
@Override
@Before
protected void setUp() {
MockitoAnnotations.initMocks(this);
_mgmtServer._eventDao = _eventDao;
_mgmtServer._accountMgr = _accountMgr;
doNothing().when(_accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
when(_eventDao.listToArchiveOrDeleteEvents(anyList(), anyString(), any(Date.class), anyLong())).thenReturn(_events);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testInjected() throws Exception {
s_logger.info("Starting test to archive and delete events");
archiveEvents();
deleteEvents();
s_logger.info("archive/delete events: TEST PASSED");
}
protected void archiveEvents() {
// archive alerts
doNothing().when(_eventDao).archiveEvents(_events);
}
protected void deleteEvents() {
// delete alerts
}
}