[AB-215] adding create alias and delete alias commands to create service specific aliases for commands

renaming package in commands package
defaulting to latest in docker compose build for deployment container
fixing jacoco configuration
changing that if there are no parameters required, parameters are accepted
This commit is contained in:
Sheldan
2021-03-27 13:17:27 +01:00
parent a494d4d2f2
commit 9541f907b8
135 changed files with 1904 additions and 376 deletions

View File

@@ -51,7 +51,7 @@ public class LeaveLogger implements AsyncLeaveListener {
@Override
public DefaultListenerResult execute(MemberLeaveModel model) {
String text = templateService.renderTemplateWithMap(USER_LEAVE_TEMPLATE, getUserParameter(model.getMember().getUser()), model.getLeavingUser().getServerId());
String text = templateService.renderTemplateWithMap(USER_LEAVE_TEMPLATE, getUserParameter(model.getMember().getUser()), model.getServerId());
postTargetService.sendTextInPostTarget(text, LoggingPostTarget.LEAVE_LOG, model.getServerId());
return DefaultListenerResult.PROCESSED;
}

View File

@@ -45,7 +45,7 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
log.trace("Message content was the same. Possible reason was: message was not in cache.");
return DefaultListenerResult.IGNORED;
}
log.trace("Message {} in channel {} in guild {} was edited.", messageBefore.getMessageId(), messageBefore.getChannelId(), messageBefore.getServerId());
log.trace("Message {} in channel {} in guild {} was edited.", messageBefore.getMessageId(), messageBefore.getChannelId(), model.getServerId());
TextChannel textChannel = channelService.getTextChannelFromServer(model.getServerId(), messageBefore.getChannelId());
MessageEditedLog log = MessageEditedLog
.builder()
@@ -55,8 +55,8 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
.guild(textChannel.getGuild())
.member(messageAfter.getMember())
.build();
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_EDITED_TEMPLATE, log, messageBefore.getServerId());
postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.EDIT_LOG, messageBefore.getServerId());
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_EDITED_TEMPLATE, log, model.getServerId());
postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.EDIT_LOG, model.getServerId());
return DefaultListenerResult.PROCESSED;
}

View File

@@ -49,14 +49,11 @@ public class JoinLoggerTest {
@Test
public void testExecute() {
when(serverUser.getUserId()).thenReturn(USER_ID);
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(model.getMember()).thenReturn(member);
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
testUnit.execute(model);
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(model.getServerId()).thenReturn(SERVER_ID);
String message = "text";
when(templateService.renderTemplateWithMap(eq(JoinLogger.USER_JOIN_TEMPLATE), any(), eq(SERVER_ID))).thenReturn(message);
testUnit.execute(model);
verify(postTargetService, times(1)).sendTextInPostTarget(message, LoggingPostTarget.JOIN_LOG, SERVER_ID);
}

View File

@@ -31,12 +31,6 @@ public class JoinMuteListenerTest {
@Mock
private UserInServerManagementService userInServerManagementService;
@Mock
private Member member;
@Mock
private Guild guild;
@Mock
private AUserInAServer joiningUser;
@@ -51,22 +45,22 @@ public class JoinMuteListenerTest {
@Test
public void testNonMutedUserJoins() {
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(serverUser.getUserId()).thenReturn(USER_ID);
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(false);
when(model.getMember()).thenReturn(member);
when(model.getServerId()).thenReturn(SERVER_ID);
when(model.getJoiningUser()).thenReturn(serverUser);
testUnit.execute(model);
verify(muteService, times(0)).applyMuteRole(joiningUser);
}
@Test
public void testMutedUserJoins() {
when(serverUser.getServerId()).thenReturn(SERVER_ID);
when(model.getServerId()).thenReturn(SERVER_ID);
when(serverUser.getUserId()).thenReturn(USER_ID);
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(true);
when(model.getMember()).thenReturn(member);
when(model.getJoiningUser()).thenReturn(serverUser);
testUnit.execute(model);
verify(muteService, times(1)).applyMuteRole(joiningUser);
}

View File

@@ -51,14 +51,11 @@ public class LeaveLoggerTest {
@Test
public void testExecute() {
when(leavingUser.getUserId()).thenReturn(USER_ID);
when(leavingUser.getServerId()).thenReturn(SERVER_ID);
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
when(model.getServerId()).thenReturn(SERVER_ID);
when(model.getMember()).thenReturn(member);
User user = Mockito.mock(User.class);
when(member.getUser()).thenReturn(user);
String message = "text";
when(leavingUser.getServerId()).thenReturn(SERVER_ID);
when(templateService.renderTemplateWithMap(eq(LeaveLogger.USER_LEAVE_TEMPLATE), any(), eq(SERVER_ID))).thenReturn(message);
testUnit.execute(model);
verify(postTargetService, times(1)).sendTextInPostTarget(message, LoggingPostTarget.LEAVE_LOG, SERVER_ID);

View File

@@ -94,7 +94,6 @@ public class MessageDeleteLogListenerTest {
public void testExecuteListener() {
when(deletedMessage.getAuthor()).thenReturn(cachedAuthor);
when(cachedAuthor.getAuthorId()).thenReturn(AUTHOR_ID);
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(member));
when(model.getCachedMessage()).thenReturn(deletedMessage);
when(model.getServerId()).thenReturn(SERVER_ID);

View File

@@ -51,6 +51,7 @@ public class MessageEditedListenerTest {
@Mock
private CachedMessage messageBefore;
@Mock
private MessageTextUpdatedModel model;
private static final Long SERVER_ID = 4L;
@@ -77,17 +78,16 @@ public class MessageEditedListenerTest {
Guild guild = Mockito.mock(Guild.class);
when(channel.getGuild()).thenReturn(guild);
Member author = Mockito.mock(Member.class);
CachedAuthor cachedAuthor = Mockito.mock(CachedAuthor.class);
when(cachedAuthor.getAuthorId()).thenReturn(AUTHOR_ID);
when(messageBefore.getContent()).thenReturn(content);
when(messageBefore.getServerId()).thenReturn(SERVER_ID);
when(messageBefore.getChannelId()).thenReturn(CHANNEL_ID);
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
ArgumentCaptor<MessageEditedLog> captor = ArgumentCaptor.forClass(MessageEditedLog.class);
when(templateService.renderEmbedTemplate(eq(MessageEditedListener.MESSAGE_EDITED_TEMPLATE), captor.capture(), eq(SERVER_ID))).thenReturn(messageToSend);
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(author));
when(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(channel);
when(model.getAfter()).thenReturn(messageAfter);
when(model.getBefore()).thenReturn(messageBefore);
when(messageAfter.getMember()).thenReturn(author);
when(model.getServerId()).thenReturn(SERVER_ID);
testUnit.execute(model);
verify(postTargetService, times(1)).sendEmbedInPostTarget(messageToSend, LoggingPostTarget.EDIT_LOG, SERVER_ID);
MessageEditedLog capturedValue = captor.getValue();

View File

@@ -7,6 +7,7 @@ import dev.sheldan.abstracto.moderation.repository.MuteRoleRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -46,8 +47,12 @@ public class MuteRoleManagementServiceBeanTest {
@Test
public void testCreateMuteRoleForServer() {
ARole role = Mockito.mock(ARole.class);
ArgumentCaptor<MuteRole> muteRoleCaptor = ArgumentCaptor.forClass(MuteRole.class);
MuteRole savedRole = Mockito.mock(MuteRole.class);
when(muteRoleRepository.save(muteRoleCaptor.capture())).thenReturn(savedRole);
MuteRole muteRoleForServer = testUnit.createMuteRoleForServer(server, role);
verifyRoleSaved(role, muteRoleForServer, 1);
Assert.assertEquals(savedRole, muteRoleForServer);
Assert.assertEquals(role, muteRoleCaptor.getValue().getRole());
}
@Test
@@ -67,8 +72,12 @@ public class MuteRoleManagementServiceBeanTest {
public void testSetMuteRoleWithoutPrevious() {
ARole role = Mockito.mock(ARole.class);
when(muteRoleRepository.existsByRoleServer(server)).thenReturn(false);
ArgumentCaptor<MuteRole> muteRoleCaptor = ArgumentCaptor.forClass(MuteRole.class);
MuteRole savedRole = Mockito.mock(MuteRole.class);
when(muteRoleRepository.save(muteRoleCaptor.capture())).thenReturn(savedRole);
MuteRole muteRole = testUnit.setMuteRoleForServer(server, role);
verifyRoleSaved(role, muteRole, 1);
Assert.assertEquals(savedRole, muteRole);
Assert.assertEquals(role, muteRoleCaptor.getValue().getRole());
}
@Test
@@ -76,16 +85,11 @@ public class MuteRoleManagementServiceBeanTest {
ARole role = Mockito.mock(ARole.class);
when(muteRoleRepository.existsByRoleServer(server)).thenReturn(true);
MuteRole existingRole = Mockito.mock(MuteRole.class);
when(existingRole.getRole()).thenReturn(role);
when(muteRoleRepository.findByRoleServer(server)).thenReturn(existingRole);
MuteRole muteRole = testUnit.setMuteRoleForServer(server, role);
verifyRoleSaved(role, muteRole, 0);
testUnit.setMuteRoleForServer(server, role);
verify(existingRole, times(1)).setRole(role);
}
private void verifyRoleSaved(ARole role, MuteRole muteRoleForServer, Integer saveCount) {
Assert.assertEquals(role, muteRoleForServer.getRole());
verify(muteRoleRepository, times(saveCount)).save(muteRoleForServer);
}
}

View File

@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.moderation.repository.UserNoteRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -46,10 +47,14 @@ public class UserNoteManagementServiceBeanTest {
AUser user = Mockito.mock(AUser.class);
when(userInAServer.getUserReference()).thenReturn(user);
when(userInAServer.getServerReference()).thenReturn(server);
UserNote savedNote = Mockito.mock(UserNote.class);
ArgumentCaptor<UserNote> noteCaptor = ArgumentCaptor.forClass(UserNote.class);
when(userNoteRepository.save(noteCaptor.capture())).thenReturn(savedNote);
UserNote userNote = testUnit.createUserNote(userInAServer, NOTE_TEXT);
verify(userNoteRepository, times(1)).save(userNote);
Assert.assertEquals(userInAServer, userNote.getUser());
Assert.assertEquals(NOTE_TEXT, userNote.getNote());
Assert.assertEquals(savedNote, userNote);
UserNote capturedNote = noteCaptor.getValue();
Assert.assertEquals(userInAServer, capturedNote.getUser());
Assert.assertEquals(NOTE_TEXT, capturedNote.getNote());
}
@Test

View File

@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.moderation.repository.WarnRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -47,12 +48,16 @@ public class WarnManagementServiceBeanTest {
when(warningUser.getUserReference()).thenReturn(user);
when(warnedUser.getUserReference()).thenReturn(user);
String reason = "REASON";
ArgumentCaptor<Warning> warningArgumentCaptor = ArgumentCaptor.forClass(Warning.class);
Warning savedWarning = Mockito.mock(Warning.class);
when(warnRepository.save(warningArgumentCaptor.capture())).thenReturn(savedWarning);
Warning warning = testUnit.createWarning(warnedUser, warningUser, reason, 8L);
Assert.assertEquals(warningUser, warning.getWarningUser());
Assert.assertEquals(warnedUser, warning.getWarnedUser());
Assert.assertEquals(reason, warning.getReason());
Assert.assertFalse(warning.getDecayed());
verify(warnRepository, times(1)).save(warning);
Assert.assertEquals(savedWarning, warning);
Warning capturedWarning = warningArgumentCaptor.getValue();
Assert.assertEquals(warningUser, capturedWarning.getWarningUser());
Assert.assertEquals(warnedUser, capturedWarning.getWarnedUser());
Assert.assertEquals(reason, capturedWarning.getReason());
Assert.assertFalse(capturedWarning.getDecayed());
}
@Test