package org.sagebionetworks.message.workers;

import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sagebionetworks.common.util.progress.ProgressCallback;
import org.sagebionetworks.repo.manager.UserManager;
import org.sagebionetworks.repo.manager.message.BroadcastMessageManager;
import org.sagebionetworks.repo.model.AuthorizationConstants.BOOTSTRAP_PRINCIPAL;
import org.sagebionetworks.repo.model.UserInfo;
import org.sagebionetworks.repo.model.message.ChangeMessage;
import org.sagebionetworks.workers.util.aws.message.RecoverableMessageException;
import org.springframework.test.util.ReflectionTestUtils;

public class BroadcastMessageWorkerTest {

	@Mock
	private BroadcastMessageManager mockBroadcastManager;
	@Mock
	private UserManager mockUserManager;
	@Mock
	private ProgressCallback<ChangeMessage> mockCallback;
	private BroadcastMessageWorker worker;

	@Before
	public void before() {
		MockitoAnnotations.initMocks(this);
		worker = new BroadcastMessageWorker();
		ReflectionTestUtils.setField(worker, "broadcastManager", mockBroadcastManager);
		ReflectionTestUtils.setField(worker, "userManager", mockUserManager);
	}

	@Test
	public void test() throws RecoverableMessageException, Exception {
		ChangeMessage fakeMessage = null;
		worker.run(mockCallback, fakeMessage);
		verify(mockUserManager).getUserInfo(BOOTSTRAP_PRINCIPAL.THE_ADMIN_USER.getPrincipalId());
		verify(mockBroadcastManager).broadcastMessage(any(UserInfo.class), eq(mockCallback), eq(fakeMessage));
	}
}

@@ -463,16 +463,66 @@
 NCIPAL;%0A
+import org.sagebionetworks.repo.model.ObjectType;%0A
 import o
@@ -622,16 +622,74 @@
 essage;%0A
+import org.sagebionetworks.repo.model.message.ChangeType;%0A
 import o
@@ -1453,11 +1453,122 @@
  = n
-ull
+ew ChangeMessage();%0A%09%09fakeMessage.setChangeType(ChangeType.CREATE);%0A%09%09fakeMessage.setObjectType(ObjectType.THREAD)
 ;%0A%09%09

update test