mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-07-14 19:40:42 +00:00
[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:
@@ -49,7 +49,7 @@ public class RollTest {
|
|||||||
Long serverId = 3L;
|
Long serverId = 3L;
|
||||||
Integer max = 10;
|
Integer max = 10;
|
||||||
when(noParameters.getGuild().getIdLong()).thenReturn(serverId);
|
when(noParameters.getGuild().getIdLong()).thenReturn(serverId);
|
||||||
when(configService.getLongValue(ROLL_DEFAULT_HIGH_KEY, serverId)).thenReturn(max.longValue());
|
when(configService.getLongValueOrConfigDefault(ROLL_DEFAULT_HIGH_KEY, serverId)).thenReturn(max.longValue());
|
||||||
when(entertainmentService.calculateRollResult(1, max)).thenReturn(result);
|
when(entertainmentService.calculateRollResult(1, max)).thenReturn(result);
|
||||||
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roll.ROLL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
when(channelService.sendEmbedTemplateInTextChannelList(eq(Roll.ROLL_RESPONSE_TEMPLATE_KEY), responseModelArgumentCaptor.capture(), eq(noParameters.getChannel()))).thenReturn(CommandTestUtilities.messageFutureList());
|
||||||
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
CompletableFuture<CommandResult> futureResult = testUnit.executeAsync(noParameters);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class EntertainmentServiceBeanTest {
|
|||||||
when(guild.getIdLong()).thenReturn(serverId);
|
when(guild.getIdLong()).thenReturn(serverId);
|
||||||
when(member.getGuild()).thenReturn(guild);
|
when(member.getGuild()).thenReturn(guild);
|
||||||
Long sides = 6L;
|
Long sides = 6L;
|
||||||
when(configService.getLongValue(EntertainmentFeatureConfig.ROULETTE_BULLETS_CONFIG_KEY, serverId)).thenReturn(sides);
|
when(configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROULETTE_BULLETS_CONFIG_KEY, serverId)).thenReturn(sides);
|
||||||
when(secureRandom.nextInt(sides.intValue())).thenReturn(randomValue);
|
when(secureRandom.nextInt(sides.intValue())).thenReturn(randomValue);
|
||||||
boolean shot = testUnit.executeRoulette(member);
|
boolean shot = testUnit.executeRoulette(member);
|
||||||
Assert.assertEquals(randomValue == 0, shot);
|
Assert.assertEquals(randomValue == 0, shot);
|
||||||
|
|||||||
@@ -37,11 +37,10 @@ public class JoiningUserRoleListener implements AsyncJoinListener {
|
|||||||
public DefaultListenerResult execute(MemberJoinModel model) {
|
public DefaultListenerResult execute(MemberJoinModel model) {
|
||||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(model.getServerId(), model.getJoiningUser().getUserId());
|
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(model.getServerId(), model.getJoiningUser().getUserId());
|
||||||
AUserExperience userExperience = userExperienceManagementService.findUserInServer(userInAServer);
|
AUserExperience userExperience = userExperienceManagementService.findUserInServer(userInAServer);
|
||||||
Long userInServerId = userInAServer.getUserInServerId();
|
|
||||||
if(userExperience != null) {
|
if(userExperience != null) {
|
||||||
log.info("User {} joined {} with previous experience. Setting up experience role again (if necessary).", model.getJoiningUser().getUserId(), model.getServerId());
|
log.info("User {} joined {} with previous experience. Setting up experience role again (if necessary).", model.getJoiningUser().getUserId(), model.getServerId());
|
||||||
userExperienceService.syncForSingleUser(userExperience).thenAccept(result ->
|
userExperienceService.syncForSingleUser(userExperience).thenAccept(result ->
|
||||||
log.info("Finished re-assigning experience for re-joining user {} in server {}.", userInServerId, model.getServerId())
|
log.info("Finished re-assigning experience for re-joining user {} in server {}.", model.getJoiningUser().getUserId(), model.getServerId())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log.info("Joined user {} in server {} does not have any previous experience. Not setting up anything.", model.getJoiningUser().getUserId(), model.getServerId());
|
log.info("Joined user {} in server {} does not have any previous experience. Not setting up anything.", model.getJoiningUser().getUserId(), model.getServerId());
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.experience.listener;
|
package dev.sheldan.abstracto.experience.listener;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||||
|
import dev.sheldan.abstracto.core.listener.ListenerExecutionResult;
|
||||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||||
import dev.sheldan.abstracto.core.models.listener.MemberJoinModel;
|
import dev.sheldan.abstracto.core.models.listener.MemberJoinModel;
|
||||||
@@ -7,6 +9,7 @@ import dev.sheldan.abstracto.core.service.management.UserInServerManagementServi
|
|||||||
import dev.sheldan.abstracto.experience.model.database.AUserExperience;
|
import dev.sheldan.abstracto.experience.model.database.AUserExperience;
|
||||||
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
|
import dev.sheldan.abstracto.experience.service.AUserExperienceService;
|
||||||
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
import dev.sheldan.abstracto.experience.service.management.UserExperienceManagementService;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -48,9 +51,9 @@ public class JoiningUserRoleListenerTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||||
when(model.getJoiningUser()).thenReturn(serverUser);
|
when(model.getJoiningUser()).thenReturn(serverUser);
|
||||||
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(aUserInAServer);
|
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(aUserInAServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +62,8 @@ public class JoiningUserRoleListenerTest {
|
|||||||
AUserExperience experience = Mockito.mock(AUserExperience.class);
|
AUserExperience experience = Mockito.mock(AUserExperience.class);
|
||||||
when(userExperienceManagementService.findUserInServer(aUserInAServer)).thenReturn(experience);
|
when(userExperienceManagementService.findUserInServer(aUserInAServer)).thenReturn(experience);
|
||||||
when(userExperienceService.syncForSingleUser(experience)).thenReturn(CompletableFuture.completedFuture(null));
|
when(userExperienceService.syncForSingleUser(experience)).thenReturn(CompletableFuture.completedFuture(null));
|
||||||
testUnit.execute(model);
|
DefaultListenerResult result = testUnit.execute(model);
|
||||||
|
Assert.assertEquals(DefaultListenerResult.PROCESSED, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ public class MessageEmbedPostManagementServiceBeanTest {
|
|||||||
AUserInAServer embeddedUser = Mockito.mock(AUserInAServer.class);
|
AUserInAServer embeddedUser = Mockito.mock(AUserInAServer.class);
|
||||||
AChannel channel = Mockito.mock(AChannel.class);
|
AChannel channel = Mockito.mock(AChannel.class);
|
||||||
AServer server = Mockito.mock(AServer.class);
|
AServer server = Mockito.mock(AServer.class);
|
||||||
when(server.getId()).thenReturn(SERVER_ID);
|
|
||||||
when(serverManagementService.loadOrCreate(SERVER_ID)).thenReturn(server);
|
when(serverManagementService.loadOrCreate(SERVER_ID)).thenReturn(server);
|
||||||
when(channelManagementService.loadChannel(EMBEDDING_CHANNEL_ID)).thenReturn(channel);
|
when(channelManagementService.loadChannel(EMBEDDING_CHANNEL_ID)).thenReturn(channel);
|
||||||
CachedMessage cachedMessage = Mockito.mock(CachedMessage.class);
|
CachedMessage cachedMessage = Mockito.mock(CachedMessage.class);
|
||||||
@@ -69,7 +68,6 @@ public class MessageEmbedPostManagementServiceBeanTest {
|
|||||||
CachedAuthor cachedAuthor = Mockito.mock(CachedAuthor.class);
|
CachedAuthor cachedAuthor = Mockito.mock(CachedAuthor.class);
|
||||||
when(cachedAuthor.getAuthorId()).thenReturn(EMBEDDED_USER_ID);
|
when(cachedAuthor.getAuthorId()).thenReturn(EMBEDDED_USER_ID);
|
||||||
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||||
when(cachedMessage.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
Message embeddingMessage = Mockito.mock(Message.class);
|
Message embeddingMessage = Mockito.mock(Message.class);
|
||||||
MessageChannel embeddingChannel = Mockito.mock(MessageChannel.class);
|
MessageChannel embeddingChannel = Mockito.mock(MessageChannel.class);
|
||||||
when(embeddingChannel.getIdLong()).thenReturn(EMBEDDING_CHANNEL_ID);
|
when(embeddingChannel.getIdLong()).thenReturn(EMBEDDING_CHANNEL_ID);
|
||||||
@@ -99,7 +97,6 @@ public class MessageEmbedPostManagementServiceBeanTest {
|
|||||||
public void testToCreateEmbedForDifferentServers() {
|
public void testToCreateEmbedForDifferentServers() {
|
||||||
Long originServerId = 4L;
|
Long originServerId = 4L;
|
||||||
AServer originalServer = Mockito.mock(AServer.class);
|
AServer originalServer = Mockito.mock(AServer.class);
|
||||||
when(originalServer.getId()).thenReturn(originServerId);
|
|
||||||
AServer embeddingServer = Mockito.mock(AServer.class);
|
AServer embeddingServer = Mockito.mock(AServer.class);
|
||||||
when(embeddingServer.getId()).thenReturn(SERVER_ID);
|
when(embeddingServer.getId()).thenReturn(SERVER_ID);
|
||||||
AUserInAServer embeddingUser = Mockito.mock(AUserInAServer.class);
|
AUserInAServer embeddingUser = Mockito.mock(AUserInAServer.class);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class LeaveLogger implements AsyncLeaveListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultListenerResult execute(MemberLeaveModel model) {
|
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());
|
postTargetService.sendTextInPostTarget(text, LoggingPostTarget.LEAVE_LOG, model.getServerId());
|
||||||
return DefaultListenerResult.PROCESSED;
|
return DefaultListenerResult.PROCESSED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
|
|||||||
log.trace("Message content was the same. Possible reason was: message was not in cache.");
|
log.trace("Message content was the same. Possible reason was: message was not in cache.");
|
||||||
return DefaultListenerResult.IGNORED;
|
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());
|
TextChannel textChannel = channelService.getTextChannelFromServer(model.getServerId(), messageBefore.getChannelId());
|
||||||
MessageEditedLog log = MessageEditedLog
|
MessageEditedLog log = MessageEditedLog
|
||||||
.builder()
|
.builder()
|
||||||
@@ -55,8 +55,8 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
|
|||||||
.guild(textChannel.getGuild())
|
.guild(textChannel.getGuild())
|
||||||
.member(messageAfter.getMember())
|
.member(messageAfter.getMember())
|
||||||
.build();
|
.build();
|
||||||
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_EDITED_TEMPLATE, log, messageBefore.getServerId());
|
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_EDITED_TEMPLATE, log, model.getServerId());
|
||||||
postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.EDIT_LOG, messageBefore.getServerId());
|
postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.EDIT_LOG, model.getServerId());
|
||||||
return DefaultListenerResult.PROCESSED;
|
return DefaultListenerResult.PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,14 +49,11 @@ public class JoinLoggerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecute() {
|
public void testExecute() {
|
||||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
|
||||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(model.getMember()).thenReturn(member);
|
when(model.getMember()).thenReturn(member);
|
||||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
testUnit.execute(model);
|
|
||||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
String message = "text";
|
String message = "text";
|
||||||
when(templateService.renderTemplateWithMap(eq(JoinLogger.USER_JOIN_TEMPLATE), any(), eq(SERVER_ID))).thenReturn(message);
|
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);
|
verify(postTargetService, times(1)).sendTextInPostTarget(message, LoggingPostTarget.JOIN_LOG, SERVER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,6 @@ public class JoinMuteListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private UserInServerManagementService userInServerManagementService;
|
private UserInServerManagementService userInServerManagementService;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Member member;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Guild guild;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private AUserInAServer joiningUser;
|
private AUserInAServer joiningUser;
|
||||||
|
|
||||||
@@ -51,22 +45,22 @@ public class JoinMuteListenerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonMutedUserJoins() {
|
public void testNonMutedUserJoins() {
|
||||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||||
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||||
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(false);
|
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);
|
testUnit.execute(model);
|
||||||
verify(muteService, times(0)).applyMuteRole(joiningUser);
|
verify(muteService, times(0)).applyMuteRole(joiningUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMutedUserJoins() {
|
public void testMutedUserJoins() {
|
||||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||||
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||||
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(true);
|
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(true);
|
||||||
when(model.getMember()).thenReturn(member);
|
when(model.getJoiningUser()).thenReturn(serverUser);
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(muteService, times(1)).applyMuteRole(joiningUser);
|
verify(muteService, times(1)).applyMuteRole(joiningUser);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,14 +51,11 @@ public class LeaveLoggerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecute() {
|
public void testExecute() {
|
||||||
when(leavingUser.getUserId()).thenReturn(USER_ID);
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(leavingUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
|
||||||
when(model.getMember()).thenReturn(member);
|
when(model.getMember()).thenReturn(member);
|
||||||
User user = Mockito.mock(User.class);
|
User user = Mockito.mock(User.class);
|
||||||
when(member.getUser()).thenReturn(user);
|
when(member.getUser()).thenReturn(user);
|
||||||
String message = "text";
|
String message = "text";
|
||||||
when(leavingUser.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(templateService.renderTemplateWithMap(eq(LeaveLogger.USER_LEAVE_TEMPLATE), any(), eq(SERVER_ID))).thenReturn(message);
|
when(templateService.renderTemplateWithMap(eq(LeaveLogger.USER_LEAVE_TEMPLATE), any(), eq(SERVER_ID))).thenReturn(message);
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(postTargetService, times(1)).sendTextInPostTarget(message, LoggingPostTarget.LEAVE_LOG, SERVER_ID);
|
verify(postTargetService, times(1)).sendTextInPostTarget(message, LoggingPostTarget.LEAVE_LOG, SERVER_ID);
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ public class MessageDeleteLogListenerTest {
|
|||||||
public void testExecuteListener() {
|
public void testExecuteListener() {
|
||||||
when(deletedMessage.getAuthor()).thenReturn(cachedAuthor);
|
when(deletedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||||
when(cachedAuthor.getAuthorId()).thenReturn(AUTHOR_ID);
|
when(cachedAuthor.getAuthorId()).thenReturn(AUTHOR_ID);
|
||||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||||
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
||||||
when(model.getServerId()).thenReturn(SERVER_ID);
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public class MessageEditedListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private CachedMessage messageBefore;
|
private CachedMessage messageBefore;
|
||||||
|
|
||||||
|
@Mock
|
||||||
private MessageTextUpdatedModel model;
|
private MessageTextUpdatedModel model;
|
||||||
|
|
||||||
private static final Long SERVER_ID = 4L;
|
private static final Long SERVER_ID = 4L;
|
||||||
@@ -77,17 +78,16 @@ public class MessageEditedListenerTest {
|
|||||||
Guild guild = Mockito.mock(Guild.class);
|
Guild guild = Mockito.mock(Guild.class);
|
||||||
when(channel.getGuild()).thenReturn(guild);
|
when(channel.getGuild()).thenReturn(guild);
|
||||||
Member author = Mockito.mock(Member.class);
|
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.getContent()).thenReturn(content);
|
||||||
when(messageBefore.getServerId()).thenReturn(SERVER_ID);
|
when(messageBefore.getChannelId()).thenReturn(CHANNEL_ID);
|
||||||
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
|
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
|
||||||
ArgumentCaptor<MessageEditedLog> captor = ArgumentCaptor.forClass(MessageEditedLog.class);
|
ArgumentCaptor<MessageEditedLog> captor = ArgumentCaptor.forClass(MessageEditedLog.class);
|
||||||
when(templateService.renderEmbedTemplate(eq(MessageEditedListener.MESSAGE_EDITED_TEMPLATE), captor.capture(), eq(SERVER_ID))).thenReturn(messageToSend);
|
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(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(channel);
|
||||||
when(model.getAfter()).thenReturn(messageAfter);
|
when(model.getAfter()).thenReturn(messageAfter);
|
||||||
when(model.getBefore()).thenReturn(messageBefore);
|
when(model.getBefore()).thenReturn(messageBefore);
|
||||||
|
when(messageAfter.getMember()).thenReturn(author);
|
||||||
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(postTargetService, times(1)).sendEmbedInPostTarget(messageToSend, LoggingPostTarget.EDIT_LOG, SERVER_ID);
|
verify(postTargetService, times(1)).sendEmbedInPostTarget(messageToSend, LoggingPostTarget.EDIT_LOG, SERVER_ID);
|
||||||
MessageEditedLog capturedValue = captor.getValue();
|
MessageEditedLog capturedValue = captor.getValue();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import dev.sheldan.abstracto.moderation.repository.MuteRoleRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -46,8 +47,12 @@ public class MuteRoleManagementServiceBeanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateMuteRoleForServer() {
|
public void testCreateMuteRoleForServer() {
|
||||||
ARole role = Mockito.mock(ARole.class);
|
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);
|
MuteRole muteRoleForServer = testUnit.createMuteRoleForServer(server, role);
|
||||||
verifyRoleSaved(role, muteRoleForServer, 1);
|
Assert.assertEquals(savedRole, muteRoleForServer);
|
||||||
|
Assert.assertEquals(role, muteRoleCaptor.getValue().getRole());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,8 +72,12 @@ public class MuteRoleManagementServiceBeanTest {
|
|||||||
public void testSetMuteRoleWithoutPrevious() {
|
public void testSetMuteRoleWithoutPrevious() {
|
||||||
ARole role = Mockito.mock(ARole.class);
|
ARole role = Mockito.mock(ARole.class);
|
||||||
when(muteRoleRepository.existsByRoleServer(server)).thenReturn(false);
|
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);
|
MuteRole muteRole = testUnit.setMuteRoleForServer(server, role);
|
||||||
verifyRoleSaved(role, muteRole, 1);
|
Assert.assertEquals(savedRole, muteRole);
|
||||||
|
Assert.assertEquals(role, muteRoleCaptor.getValue().getRole());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,16 +85,11 @@ public class MuteRoleManagementServiceBeanTest {
|
|||||||
ARole role = Mockito.mock(ARole.class);
|
ARole role = Mockito.mock(ARole.class);
|
||||||
when(muteRoleRepository.existsByRoleServer(server)).thenReturn(true);
|
when(muteRoleRepository.existsByRoleServer(server)).thenReturn(true);
|
||||||
MuteRole existingRole = Mockito.mock(MuteRole.class);
|
MuteRole existingRole = Mockito.mock(MuteRole.class);
|
||||||
when(existingRole.getRole()).thenReturn(role);
|
|
||||||
when(muteRoleRepository.findByRoleServer(server)).thenReturn(existingRole);
|
when(muteRoleRepository.findByRoleServer(server)).thenReturn(existingRole);
|
||||||
MuteRole muteRole = testUnit.setMuteRoleForServer(server, role);
|
testUnit.setMuteRoleForServer(server, role);
|
||||||
verifyRoleSaved(role, muteRole, 0);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.moderation.repository.UserNoteRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -46,10 +47,14 @@ public class UserNoteManagementServiceBeanTest {
|
|||||||
AUser user = Mockito.mock(AUser.class);
|
AUser user = Mockito.mock(AUser.class);
|
||||||
when(userInAServer.getUserReference()).thenReturn(user);
|
when(userInAServer.getUserReference()).thenReturn(user);
|
||||||
when(userInAServer.getServerReference()).thenReturn(server);
|
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);
|
UserNote userNote = testUnit.createUserNote(userInAServer, NOTE_TEXT);
|
||||||
verify(userNoteRepository, times(1)).save(userNote);
|
Assert.assertEquals(savedNote, userNote);
|
||||||
Assert.assertEquals(userInAServer, userNote.getUser());
|
UserNote capturedNote = noteCaptor.getValue();
|
||||||
Assert.assertEquals(NOTE_TEXT, userNote.getNote());
|
Assert.assertEquals(userInAServer, capturedNote.getUser());
|
||||||
|
Assert.assertEquals(NOTE_TEXT, capturedNote.getNote());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.moderation.repository.WarnRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -47,12 +48,16 @@ public class WarnManagementServiceBeanTest {
|
|||||||
when(warningUser.getUserReference()).thenReturn(user);
|
when(warningUser.getUserReference()).thenReturn(user);
|
||||||
when(warnedUser.getUserReference()).thenReturn(user);
|
when(warnedUser.getUserReference()).thenReturn(user);
|
||||||
String reason = "REASON";
|
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);
|
Warning warning = testUnit.createWarning(warnedUser, warningUser, reason, 8L);
|
||||||
Assert.assertEquals(warningUser, warning.getWarningUser());
|
Assert.assertEquals(savedWarning, warning);
|
||||||
Assert.assertEquals(warnedUser, warning.getWarnedUser());
|
Warning capturedWarning = warningArgumentCaptor.getValue();
|
||||||
Assert.assertEquals(reason, warning.getReason());
|
Assert.assertEquals(warningUser, capturedWarning.getWarningUser());
|
||||||
Assert.assertFalse(warning.getDecayed());
|
Assert.assertEquals(warnedUser, capturedWarning.getWarnedUser());
|
||||||
verify(warnRepository, times(1)).save(warning);
|
Assert.assertEquals(reason, capturedWarning.getReason());
|
||||||
|
Assert.assertFalse(capturedWarning.getDecayed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ public class ModMailMessageDeletedListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeleteNonDuplicatedMessage() {
|
public void testDeleteNonDuplicatedMessage() {
|
||||||
when(deletedMessage.getMessageId()).thenReturn(DELETED_MESSAGE_ID);
|
when(deletedMessage.getMessageId()).thenReturn(DELETED_MESSAGE_ID);
|
||||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(modMailMessageManagementService.getByMessageIdOptional(DELETED_MESSAGE_ID)).thenReturn(Optional.of(modMailMessage));
|
when(modMailMessageManagementService.getByMessageIdOptional(DELETED_MESSAGE_ID)).thenReturn(Optional.of(modMailMessage));
|
||||||
ModMailThread thread = Mockito.mock(ModMailThread.class);
|
ModMailThread thread = Mockito.mock(ModMailThread.class);
|
||||||
AUserInAServer targetUsInAServer = Mockito.mock(AUserInAServer.class);
|
AUserInAServer targetUsInAServer = Mockito.mock(AUserInAServer.class);
|
||||||
@@ -100,6 +99,7 @@ public class ModMailMessageDeletedListenerTest {
|
|||||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(targetMember));
|
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(targetMember));
|
||||||
when(messageService.deleteMessageInChannelWithUser(targetUser, CREATED_MESSAGE_ID_2)).thenReturn(CompletableFuture.completedFuture(null));
|
when(messageService.deleteMessageInChannelWithUser(targetUser, CREATED_MESSAGE_ID_2)).thenReturn(CompletableFuture.completedFuture(null));
|
||||||
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
||||||
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(messageService, times(0)).deleteMessageInChannelInServer(eq(SERVER_ID), anyLong(), any());
|
verify(messageService, times(0)).deleteMessageInChannelInServer(eq(SERVER_ID), anyLong(), any());
|
||||||
verify(self, times(1)).removeMessageFromThread(DELETED_MESSAGE_ID);
|
verify(self, times(1)).removeMessageFromThread(DELETED_MESSAGE_ID);
|
||||||
@@ -108,7 +108,6 @@ public class ModMailMessageDeletedListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeleteDuplicatedMessage() {
|
public void testDeleteDuplicatedMessage() {
|
||||||
when(deletedMessage.getMessageId()).thenReturn(DELETED_MESSAGE_ID);
|
when(deletedMessage.getMessageId()).thenReturn(DELETED_MESSAGE_ID);
|
||||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
when(modMailMessageManagementService.getByMessageIdOptional(DELETED_MESSAGE_ID)).thenReturn(Optional.of(modMailMessage));
|
when(modMailMessageManagementService.getByMessageIdOptional(DELETED_MESSAGE_ID)).thenReturn(Optional.of(modMailMessage));
|
||||||
ModMailThread thread = Mockito.mock(ModMailThread.class);
|
ModMailThread thread = Mockito.mock(ModMailThread.class);
|
||||||
AUserInAServer targetUsInAServer = Mockito.mock(AUserInAServer.class);
|
AUserInAServer targetUsInAServer = Mockito.mock(AUserInAServer.class);
|
||||||
@@ -127,6 +126,7 @@ public class ModMailMessageDeletedListenerTest {
|
|||||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(targetMember));
|
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(targetMember));
|
||||||
when(messageService.deleteMessageInChannelWithUser(targetUser, CREATED_MESSAGE_ID_2)).thenReturn(CompletableFuture.completedFuture(null));
|
when(messageService.deleteMessageInChannelWithUser(targetUser, CREATED_MESSAGE_ID_2)).thenReturn(CompletableFuture.completedFuture(null));
|
||||||
when(messageService.deleteMessageInChannelInServer(SERVER_ID, CHANNEL_ID, CREATED_MESSAGE_ID_1)).thenReturn(CompletableFuture.completedFuture(null));
|
when(messageService.deleteMessageInChannelInServer(SERVER_ID, CHANNEL_ID, CREATED_MESSAGE_ID_1)).thenReturn(CompletableFuture.completedFuture(null));
|
||||||
|
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
when(model.getCachedMessage()).thenReturn(deletedMessage);
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(self, times(1)).removeMessageFromThread(DELETED_MESSAGE_ID);
|
verify(self, times(1)).removeMessageFromThread(DELETED_MESSAGE_ID);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import dev.sheldan.abstracto.remind.repository.ReminderRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -56,15 +57,19 @@ public class ReminderManagementServiceBeanTest {
|
|||||||
String reminderText = "text";
|
String reminderText = "text";
|
||||||
Instant reminderTargetDate = Instant.ofEpochSecond(1590615937);
|
Instant reminderTargetDate = Instant.ofEpochSecond(1590615937);
|
||||||
Long messageId = 5L;
|
Long messageId = 5L;
|
||||||
|
ArgumentCaptor<Reminder> reminderArgumentCaptor = ArgumentCaptor.forClass(Reminder.class);
|
||||||
|
Reminder savedReminder = Mockito.mock(Reminder.class);
|
||||||
|
when(reminderRepository.save(reminderArgumentCaptor.capture())).thenReturn(savedReminder);
|
||||||
Reminder createdReminder = testUnit.createReminder(serverAChannelAUser, reminderText, reminderTargetDate, messageId);
|
Reminder createdReminder = testUnit.createReminder(serverAChannelAUser, reminderText, reminderTargetDate, messageId);
|
||||||
Assert.assertEquals(messageId, createdReminder.getMessageId());
|
Assert.assertEquals(savedReminder, createdReminder);
|
||||||
Assert.assertEquals(aUserInAServer, createdReminder.getRemindedUser());
|
Reminder capturedReminder = reminderArgumentCaptor.getValue();
|
||||||
Assert.assertEquals(server, createdReminder.getServer());
|
Assert.assertEquals(messageId, capturedReminder.getMessageId());
|
||||||
Assert.assertEquals(reminderText, createdReminder.getText());
|
Assert.assertEquals(aUserInAServer, capturedReminder.getRemindedUser());
|
||||||
Assert.assertEquals(reminderTargetDate, createdReminder.getTargetDate());
|
Assert.assertEquals(server, capturedReminder.getServer());
|
||||||
Assert.assertEquals(channel, createdReminder.getChannel());
|
Assert.assertEquals(reminderText, capturedReminder.getText());
|
||||||
Assert.assertFalse(createdReminder.isReminded());
|
Assert.assertEquals(reminderTargetDate, capturedReminder.getTargetDate());
|
||||||
verify(reminderRepository, times(1)).save(createdReminder);
|
Assert.assertEquals(channel, capturedReminder.getChannel());
|
||||||
|
Assert.assertFalse(capturedReminder.isReminded());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.repostdetection.service.RepostServiceBean;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -55,11 +56,15 @@ public class PostedImageManagementBeanTest {
|
|||||||
when(serverAChannelAUser.getGuild()).thenReturn(server);
|
when(serverAChannelAUser.getGuild()).thenReturn(server);
|
||||||
when(serverAChannelAUser.getChannel()).thenReturn(channel);
|
when(serverAChannelAUser.getChannel()).thenReturn(channel);
|
||||||
when(serverAChannelAUser.getAUserInAServer()).thenReturn(aUserInAServer);
|
when(serverAChannelAUser.getAUserInAServer()).thenReturn(aUserInAServer);
|
||||||
|
ArgumentCaptor<PostedImage> postedImageArgumentCaptor = ArgumentCaptor.forClass(PostedImage.class);
|
||||||
|
PostedImage savedPost = Mockito.mock(PostedImage.class);
|
||||||
|
when(postedImageRepository.save(postedImageArgumentCaptor.capture())).thenReturn(savedPost);
|
||||||
PostedImage createdPost = testUnit.createPost(serverAChannelAUser, MESSAGE_ID, HASH, INDEX);
|
PostedImage createdPost = testUnit.createPost(serverAChannelAUser, MESSAGE_ID, HASH, INDEX);
|
||||||
Assert.assertEquals(HASH, createdPost.getImageHash());
|
Assert.assertEquals(savedPost, createdPost);
|
||||||
Assert.assertEquals(INDEX, createdPost.getPostId().getPosition());
|
PostedImage capturedPost = postedImageArgumentCaptor.getValue();
|
||||||
Assert.assertEquals(MESSAGE_ID, createdPost.getPostId().getMessageId());
|
Assert.assertEquals(HASH, capturedPost.getImageHash());
|
||||||
verify(postedImageRepository, times(1)).save(createdPost);
|
Assert.assertEquals(INDEX, capturedPost.getPostId().getPosition());
|
||||||
|
Assert.assertEquals(MESSAGE_ID, capturedPost.getPostId().getMessageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import dev.sheldan.abstracto.repostdetection.repository.RepostCheckChannelReposi
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.*;
|
||||||
import org.mockito.Captor;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -105,12 +102,14 @@ public class RepostCheckChannelGroupManagementBeanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateRepostCheckChannelGroup() {
|
public void testCreateRepostCheckChannelGroup() {
|
||||||
when(aChannelGroup.getId()).thenReturn(CHANNEL_GROUP_ID);
|
when(aChannelGroup.getId()).thenReturn(CHANNEL_GROUP_ID);
|
||||||
|
RepostCheckChannelGroup savedGroup = Mockito.mock(RepostCheckChannelGroup.class);
|
||||||
|
when(repository.save(checkChannelGroupArgumentCaptor.capture())).thenReturn(savedGroup);
|
||||||
RepostCheckChannelGroup createdCheckChannelGroup = testUnit.createRepostCheckChannelGroup(aChannelGroup);
|
RepostCheckChannelGroup createdCheckChannelGroup = testUnit.createRepostCheckChannelGroup(aChannelGroup);
|
||||||
verify(repository, times(1)).save(checkChannelGroupArgumentCaptor.capture());
|
Assert.assertEquals(savedGroup, createdCheckChannelGroup);
|
||||||
Assert.assertEquals(checkChannelGroupArgumentCaptor.getValue(), createdCheckChannelGroup);
|
RepostCheckChannelGroup capturedGroup = checkChannelGroupArgumentCaptor.getValue();
|
||||||
Assert.assertTrue(createdCheckChannelGroup.getCheckEnabled());
|
Assert.assertTrue(capturedGroup.getCheckEnabled());
|
||||||
Assert.assertEquals(CHANNEL_GROUP_ID, createdCheckChannelGroup.getId());
|
Assert.assertEquals(CHANNEL_GROUP_ID, capturedGroup.getId());
|
||||||
Assert.assertEquals(aChannelGroup, createdCheckChannelGroup.getChannelGroup());
|
Assert.assertEquals(aChannelGroup, capturedGroup.getChannelGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = RepostCheckChannelGroupNotFoundException.class)
|
@Test(expected = RepostCheckChannelGroupNotFoundException.class)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@@ -149,9 +150,9 @@ public class StarAddedListenerTest {
|
|||||||
public void testAddingEmoteReachingThreshold() {
|
public void testAddingEmoteReachingThreshold() {
|
||||||
Long requiredStars = 1L;
|
Long requiredStars = 1L;
|
||||||
setupActingAndAuthor();
|
setupActingAndAuthor();
|
||||||
|
when(starboardService.createStarboardPost(any(CachedMessage.class), anyList(), eq(userInServerActing), eq(userInAServer))).thenReturn(CompletableFuture.completedFuture(null));
|
||||||
executeAddingTest(requiredStars, null);
|
executeAddingTest(requiredStars, null);
|
||||||
verify(metricService, times(2)).incrementCounter(any());
|
verify(metricService, times(2)).incrementCounter(any());
|
||||||
verify(starboardService, times(1)).createStarboardPost(any(CachedMessage.class), anyList(), eq(userInServerActing), eq(userInAServer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ public class StarboardServiceBeanTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private AUser aUser;
|
private AUser aUser;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private StarboardPostCreatedListenerManager starboardPostCreatedListenerManager;
|
||||||
|
|
||||||
private static final Long STARRED_USER_ID = 5L;
|
private static final Long STARRED_USER_ID = 5L;
|
||||||
private static final Long STARRED_SERVER_USER_ID = 2L;
|
private static final Long STARRED_SERVER_USER_ID = 2L;
|
||||||
private static final Long SERVER_ID = 6L;
|
private static final Long SERVER_ID = 6L;
|
||||||
@@ -194,13 +197,10 @@ public class StarboardServiceBeanTest {
|
|||||||
CachedMessage message = Mockito.mock(CachedMessage.class);
|
CachedMessage message = Mockito.mock(CachedMessage.class);
|
||||||
List<Long> userExceptAuthorIds = Arrays.asList(FIRST_USER_IN_SERVER_ID, SECOND_USER_IN_SERVER_ID);
|
List<Long> userExceptAuthorIds = Arrays.asList(FIRST_USER_IN_SERVER_ID, SECOND_USER_IN_SERVER_ID);
|
||||||
List<CompletableFuture<Message>> futures = Arrays.asList(CompletableFuture.completedFuture(sendPost));
|
List<CompletableFuture<Message>> futures = Arrays.asList(CompletableFuture.completedFuture(sendPost));
|
||||||
when(sendPost.getGuild()).thenReturn(guild);
|
|
||||||
when(sendPost.getChannel()).thenReturn(mockedTextChannel);
|
|
||||||
when(sendPost.getIdLong()).thenReturn(MESSAGE_ID);
|
when(sendPost.getIdLong()).thenReturn(MESSAGE_ID);
|
||||||
when(userInServerManagementService.loadUserOptional(STARRED_SERVER_USER_ID)).thenReturn(Optional.of(starredUser));
|
when(userInServerManagementService.loadUserOptional(STARRED_SERVER_USER_ID)).thenReturn(Optional.of(starredUser));
|
||||||
when(userInServerManagementService.loadUserOptional(FIRST_USER_IN_SERVER_ID)).thenReturn(Optional.of(userReacting));
|
when(userInServerManagementService.loadUserOptional(FIRST_USER_IN_SERVER_ID)).thenReturn(Optional.of(userReacting));
|
||||||
when(userReacting.getUserInServerId()).thenReturn(FIRST_USER_IN_SERVER_ID);
|
when(userReacting.getUserInServerId()).thenReturn(FIRST_USER_IN_SERVER_ID);
|
||||||
when(userReacting.getUserReference()).thenReturn(aUser);
|
|
||||||
AChannel channel = Mockito.mock(AChannel.class);
|
AChannel channel = Mockito.mock(AChannel.class);
|
||||||
when(channelManagementService.loadChannel(CHANNEL_ID)).thenReturn(channel);
|
when(channelManagementService.loadChannel(CHANNEL_ID)).thenReturn(channel);
|
||||||
StarboardPost post = Mockito.mock(StarboardPost.class);
|
StarboardPost post = Mockito.mock(StarboardPost.class);
|
||||||
@@ -208,13 +208,13 @@ public class StarboardServiceBeanTest {
|
|||||||
AUserInAServer secondStarrerUserObj = Mockito.mock(AUserInAServer.class);
|
AUserInAServer secondStarrerUserObj = Mockito.mock(AUserInAServer.class);
|
||||||
when(userInServerManagementService.loadUserOptional(SECOND_USER_IN_SERVER_ID)).thenReturn(Optional.of(secondStarrerUserObj));
|
when(userInServerManagementService.loadUserOptional(SECOND_USER_IN_SERVER_ID)).thenReturn(Optional.of(secondStarrerUserObj));
|
||||||
when(secondStarrerUserObj.getUserInServerId()).thenReturn(SECOND_USER_IN_SERVER_ID);
|
when(secondStarrerUserObj.getUserInServerId()).thenReturn(SECOND_USER_IN_SERVER_ID);
|
||||||
when(secondStarrerUserObj.getUserReference()).thenReturn(aUser);
|
|
||||||
testUnit.persistPost(message, userExceptAuthorIds, futures, CHANNEL_ID, STARRED_SERVER_USER_ID, STARRING_USER_ID);
|
testUnit.persistPost(message, userExceptAuthorIds, futures, CHANNEL_ID, STARRED_SERVER_USER_ID, STARRING_USER_ID);
|
||||||
verify(starboardPostReactorManagementService, times(2)).addReactor(eq(post), userInAServerArgumentCaptor.capture());
|
verify(starboardPostReactorManagementService, times(2)).addReactor(eq(post), userInAServerArgumentCaptor.capture());
|
||||||
List<AUserInAServer> addedReactors = userInAServerArgumentCaptor.getAllValues();
|
List<AUserInAServer> addedReactors = userInAServerArgumentCaptor.getAllValues();
|
||||||
Assert.assertEquals(FIRST_USER_IN_SERVER_ID, addedReactors.get(0).getUserInServerId());
|
Assert.assertEquals(FIRST_USER_IN_SERVER_ID, addedReactors.get(0).getUserInServerId());
|
||||||
Assert.assertEquals(SECOND_USER_IN_SERVER_ID, addedReactors.get(1).getUserInServerId());
|
Assert.assertEquals(SECOND_USER_IN_SERVER_ID, addedReactors.get(1).getUserInServerId());
|
||||||
Assert.assertEquals(2, addedReactors.size());
|
Assert.assertEquals(2, addedReactors.size());
|
||||||
|
verify(starboardPostCreatedListenerManager, times(1)).sendStarboardPostCreatedEvent(STARRING_USER_ID, post);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -242,7 +242,7 @@ public class StarboardServiceBeanTest {
|
|||||||
when(config.getLongValue()).thenReturn(1L);
|
when(config.getLongValue()).thenReturn(1L);
|
||||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + 1)).thenReturn(config);
|
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + 1)).thenReturn(config);
|
||||||
when(starboardPostManagementService.findByStarboardPostMessageId(starboardPostId)).thenReturn(Optional.of(post));
|
when(starboardPostManagementService.findByStarboardPostId(starboardPostId)).thenReturn(Optional.of(post));
|
||||||
when(userService.retrieveUserForId(STARRED_USER_ID)).thenReturn(CompletableFuture.completedFuture(starredJdaUser));
|
when(userService.retrieveUserForId(STARRED_USER_ID)).thenReturn(CompletableFuture.completedFuture(starredJdaUser));
|
||||||
List<AUserInAServer > userExceptAuthor = new ArrayList<>();
|
List<AUserInAServer > userExceptAuthor = new ArrayList<>();
|
||||||
CompletableFuture<Void> future = testUnit.updateStarboardPost(post, message, userExceptAuthor);
|
CompletableFuture<Void> future = testUnit.updateStarboardPost(post, message, userExceptAuthor);
|
||||||
@@ -280,17 +280,16 @@ public class StarboardServiceBeanTest {
|
|||||||
Integer limit = 3;
|
Integer limit = 3;
|
||||||
AChannel channel = Mockito.mock(AChannel.class);
|
AChannel channel = Mockito.mock(AChannel.class);
|
||||||
when(server.getId()).thenReturn(SERVER_ID);
|
when(server.getId()).thenReturn(SERVER_ID);
|
||||||
StarboardPostReaction reaction = Mockito.mock(StarboardPostReaction.class);
|
|
||||||
StarboardPost post1 = Mockito.mock(StarboardPost.class);
|
StarboardPost post1 = Mockito.mock(StarboardPost.class);
|
||||||
when(post1.getReactions()).thenReturn(Arrays.asList(reaction));
|
|
||||||
when(post1.getPostMessageId()).thenReturn(MESSAGE_ID);
|
when(post1.getPostMessageId()).thenReturn(MESSAGE_ID);
|
||||||
when(post1.getServer()).thenReturn(server);
|
when(post1.getServer()).thenReturn(server);
|
||||||
when(post1.getStarboardChannel()).thenReturn(channel);
|
when(post1.getStarboardChannel()).thenReturn(channel);
|
||||||
StarboardPost post2 = Mockito.mock(StarboardPost.class);
|
StarboardPost post2 = Mockito.mock(StarboardPost.class);
|
||||||
when(post2.getPostMessageId()).thenReturn(SECOND_MESSAGE_ID);
|
when(post2.getPostMessageId()).thenReturn(SECOND_MESSAGE_ID);
|
||||||
when(post2.getReactions()).thenReturn(new ArrayList<>());
|
|
||||||
when(post2.getServer()).thenReturn(server);
|
when(post2.getServer()).thenReturn(server);
|
||||||
when(post2.getStarboardChannel()).thenReturn(channel);
|
when(post2.getStarboardChannel()).thenReturn(channel);
|
||||||
|
when(starboardPostReactorManagementService.getReactorCountOfPost(post1)).thenReturn(1L);
|
||||||
|
when(starboardPostReactorManagementService.getReactorCountOfPost(post2)).thenReturn(0L);
|
||||||
List<StarboardPost> topPosts = Arrays.asList(post1, post2);
|
List<StarboardPost> topPosts = Arrays.asList(post1, post2);
|
||||||
when(starboardPostManagementService.retrieveTopPosts(SERVER_ID, limit)).thenReturn(topPosts);
|
when(starboardPostManagementService.retrieveTopPosts(SERVER_ID, limit)).thenReturn(topPosts);
|
||||||
CompletableFuture<StarStatsUser> statsUser = CompletableFuture.completedFuture(Mockito.mock(StarStatsUser.class));
|
CompletableFuture<StarStatsUser> statsUser = CompletableFuture.completedFuture(Mockito.mock(StarStatsUser.class));
|
||||||
@@ -339,10 +338,9 @@ public class StarboardServiceBeanTest {
|
|||||||
AServer server = Mockito.mock(AServer.class);
|
AServer server = Mockito.mock(AServer.class);
|
||||||
when(server.getId()).thenReturn(SERVER_ID);
|
when(server.getId()).thenReturn(SERVER_ID);
|
||||||
when(post.getServer()).thenReturn(server);
|
when(post.getServer()).thenReturn(server);
|
||||||
StarboardPostReaction reaction = Mockito.mock(StarboardPostReaction.class);
|
|
||||||
when(post.getReactions()).thenReturn(Collections.singletonList(reaction));
|
|
||||||
when(starboardChannel.getId()).thenReturn(STARBOARD_CHANNEL_ID);
|
when(starboardChannel.getId()).thenReturn(STARBOARD_CHANNEL_ID);
|
||||||
when(post.getPostMessageId()).thenReturn(MESSAGE_ID);
|
when(post.getPostMessageId()).thenReturn(MESSAGE_ID);
|
||||||
|
when(starboardPostReactorManagementService.getReactorCountOfPost(post)).thenReturn(1L);
|
||||||
when(starboardPostManagementService.retrieveTopPostsForUserInServer(SERVER_ID, STARRED_USER_ID, 3)).thenReturn(Collections.singletonList(post));
|
when(starboardPostManagementService.retrieveTopPostsForUserInServer(SERVER_ID, STARRED_USER_ID, 3)).thenReturn(Collections.singletonList(post));
|
||||||
MemberStarStatsModel returnedModel = testUnit.retrieveStarStatsForMember(starredMember);
|
MemberStarStatsModel returnedModel = testUnit.retrieveStarStatsForMember(starredMember);
|
||||||
Assert.assertEquals(receivedStars, returnedModel.getReceivedStars());
|
Assert.assertEquals(receivedStars, returnedModel.getReceivedStars());
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.starboard.repository.StarboardPostRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -67,14 +68,18 @@ public class StarboardPostManagementServiceBeanTest {
|
|||||||
when(channelManagementService.loadChannel(SOURCE_CHANNEL_ID)).thenReturn(sourceChannel);
|
when(channelManagementService.loadChannel(SOURCE_CHANNEL_ID)).thenReturn(sourceChannel);
|
||||||
AUser aUser = Mockito.mock(AUser.class);
|
AUser aUser = Mockito.mock(AUser.class);
|
||||||
when(aUserInAServer.getUserReference()).thenReturn(aUser);
|
when(aUserInAServer.getUserReference()).thenReturn(aUser);
|
||||||
|
ArgumentCaptor<StarboardPost> argumentCaptor = ArgumentCaptor.forClass(StarboardPost.class);
|
||||||
|
StarboardPost savedPost = Mockito.mock(StarboardPost.class);
|
||||||
|
when(repository.save(argumentCaptor.capture())).thenReturn(savedPost);
|
||||||
StarboardPost createdStarboardPost = testUnit.createStarboardPost(starredMessage, aUserInAServer, postInStarboard);
|
StarboardPost createdStarboardPost = testUnit.createStarboardPost(starredMessage, aUserInAServer, postInStarboard);
|
||||||
verify(repository, times(1)).save(createdStarboardPost);
|
Assert.assertEquals(savedPost, createdStarboardPost);
|
||||||
Assert.assertEquals(starboardChannel, createdStarboardPost.getStarboardChannel());
|
StarboardPost capturedPost = argumentCaptor.getValue();
|
||||||
Assert.assertEquals(starboardPostId, createdStarboardPost.getStarboardMessageId());
|
Assert.assertEquals(starboardChannel, capturedPost.getStarboardChannel());
|
||||||
Assert.assertEquals(starredMessageId, createdStarboardPost.getPostMessageId());
|
Assert.assertEquals(starboardPostId, capturedPost.getStarboardMessageId());
|
||||||
Assert.assertEquals(aUserInAServer, createdStarboardPost.getAuthor());
|
Assert.assertEquals(starredMessageId, capturedPost.getPostMessageId());
|
||||||
Assert.assertEquals(sourceChannel, createdStarboardPost.getSourceChannel());
|
Assert.assertEquals(aUserInAServer, capturedPost.getAuthor());
|
||||||
Assert.assertFalse(createdStarboardPost.isIgnored());
|
Assert.assertEquals(sourceChannel, capturedPost.getSourceChannel());
|
||||||
|
Assert.assertFalse(capturedPost.isIgnored());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -83,20 +88,21 @@ public class StarboardPostManagementServiceBeanTest {
|
|||||||
Long messageId = 6L;
|
Long messageId = 6L;
|
||||||
testUnit.setStarboardPostMessageId(post, messageId);
|
testUnit.setStarboardPostMessageId(post, messageId);
|
||||||
verify(post, times(1)).setStarboardMessageId(messageId);
|
verify(post, times(1)).setStarboardMessageId(messageId);
|
||||||
verify(repository, times(1)).save(post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrieveTopPosts() {
|
public void testRetrieveTopPosts() {
|
||||||
Integer count = 2;
|
Integer count = 2;
|
||||||
|
Long postId = 1L;
|
||||||
|
Long postId2 = 3L;
|
||||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
||||||
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
||||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
||||||
when(starboardPost2.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class)));
|
when(starboardPost2.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class)));
|
||||||
StarboardPost starboardPost3 = Mockito.mock(StarboardPost.class);
|
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2);
|
||||||
when(starboardPost3.getReactions()).thenReturn(new ArrayList<>());
|
List<Long> postIds = Arrays.asList(postId, postId2);
|
||||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2, starboardPost3);
|
when(repository.getTopStarboardPostsForServer(SERVER_ID, count)).thenReturn(postIds);
|
||||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
when(repository.findAllById(postIds)).thenReturn(posts);
|
||||||
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
||||||
Assert.assertEquals(count.intValue(), topPosts.size());
|
Assert.assertEquals(count.intValue(), topPosts.size());
|
||||||
StarboardPost topMostPost = topPosts.get(0);
|
StarboardPost topMostPost = topPosts.get(0);
|
||||||
@@ -109,6 +115,9 @@ public class StarboardPostManagementServiceBeanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRetrieveMoreThanAvailable() {
|
public void testRetrieveMoreThanAvailable() {
|
||||||
Integer count = 5;
|
Integer count = 5;
|
||||||
|
Long postId = 1L;
|
||||||
|
Long postId2 = 2L;
|
||||||
|
Long postId3 = 3L;
|
||||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
||||||
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
||||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
||||||
@@ -116,7 +125,9 @@ public class StarboardPostManagementServiceBeanTest {
|
|||||||
StarboardPost starboardPost3 = Mockito.mock(StarboardPost.class);
|
StarboardPost starboardPost3 = Mockito.mock(StarboardPost.class);
|
||||||
when(starboardPost3.getReactions()).thenReturn(new ArrayList<>());
|
when(starboardPost3.getReactions()).thenReturn(new ArrayList<>());
|
||||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2, starboardPost3);
|
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2, starboardPost3);
|
||||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
List<Long> postIds = Arrays.asList(postId, postId2, postId3);
|
||||||
|
when(repository.getTopStarboardPostsForServer(SERVER_ID, 5)).thenReturn(postIds);
|
||||||
|
when(repository.findAllById(postIds)).thenReturn(posts);
|
||||||
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
||||||
StarboardPost topMostPost = topPosts.get(0);
|
StarboardPost topMostPost = topPosts.get(0);
|
||||||
StarboardPost secondTop = topPosts.get(1);
|
StarboardPost secondTop = topPosts.get(1);
|
||||||
@@ -194,11 +205,9 @@ public class StarboardPostManagementServiceBeanTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrievePostCount() {
|
public void testRetrievePostCount() {
|
||||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
Long expectedCount = 2L;
|
||||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
when(repository.countByServer_Id(SERVER_ID)).thenReturn(expectedCount);
|
||||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2);
|
|
||||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
|
||||||
Long retrievedPostCount = testUnit.getPostCount(SERVER_ID);
|
Long retrievedPostCount = testUnit.getPostCount(SERVER_ID);
|
||||||
Assert.assertEquals(posts.size(), retrievedPostCount.intValue());
|
Assert.assertEquals(expectedCount, retrievedPostCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,17 +26,12 @@ public class DeleteTrackedEmoteListenerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private EmoteDeletedModel model;
|
private EmoteDeletedModel model;
|
||||||
|
|
||||||
private static final Long SERVER_ID = 4L;
|
|
||||||
private static final Long EMOTE_ID = 4L;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmoteDeleted() {
|
public void testEmoteDeleted() {
|
||||||
Emote emote = Mockito.mock(Emote.class);
|
Emote emote = Mockito.mock(Emote.class);
|
||||||
when(emote.getIdLong()).thenReturn(EMOTE_ID);
|
|
||||||
when(model.getEmote()).thenReturn(emote);
|
when(model.getEmote()).thenReturn(emote);
|
||||||
when(model.getServerId()).thenReturn(SERVER_ID);
|
|
||||||
testUnit.execute(model);
|
testUnit.execute(model);
|
||||||
verify(trackedEmoteManagementService, times(1)).markAsDeleted(SERVER_ID, EMOTE_ID);
|
verify(trackedEmoteManagementService, times(1)).markAsDeleted(emote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import dev.sheldan.abstracto.statistic.emote.service.TrackedEmoteService;
|
|||||||
import net.dv8tion.jda.api.entities.Emote;
|
import net.dv8tion.jda.api.entities.Emote;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import org.apache.commons.collections4.Bag;
|
||||||
|
import org.apache.commons.collections4.bag.HashBag;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -52,19 +54,19 @@ public class EmoteTrackingListenerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteOneEmote() {
|
public void testExecuteOneEmote() {
|
||||||
List<Emote> emotesBag = new ArrayList<>();
|
Bag<Emote> emotesBag = new HashBag<>();
|
||||||
emotesBag.add(emote1);
|
emotesBag.add(emote1);
|
||||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(message.getEmotes()).thenReturn(emotesBag);
|
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||||
testUnit.execute(messageReceivedModel);
|
testUnit.execute(messageReceivedModel);
|
||||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteOneEmoteMultipleTimes() {
|
public void testExecuteOneEmoteMultipleTimes() {
|
||||||
List<Emote> emotesBag = new ArrayList<>();
|
Bag<Emote> emotesBag = new HashBag<>();
|
||||||
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
||||||
when(emote2.getIdLong()).thenReturn(EMOTE_ID);
|
when(emote2.getIdLong()).thenReturn(EMOTE_ID);
|
||||||
emotesBag.add(emote1);
|
emotesBag.add(emote1);
|
||||||
@@ -72,14 +74,14 @@ public class EmoteTrackingListenerTest {
|
|||||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||||
when(message.getEmotes()).thenReturn(emotesBag);
|
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||||
testUnit.execute(messageReceivedModel);
|
testUnit.execute(messageReceivedModel);
|
||||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(any(CachedEmote.class), eq(guild), eq(2L));
|
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(any(Emote.class), eq(guild), eq(2L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteMultipleEmotes() {
|
public void testExecuteMultipleEmotes() {
|
||||||
List<Emote> emotesBag = new ArrayList<>();
|
Bag<Emote> emotesBag = new HashBag<>();
|
||||||
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
when(emote1.getIdLong()).thenReturn(EMOTE_ID);
|
||||||
when(emote2.getIdLong()).thenReturn(EMOTE_ID + 1);
|
when(emote2.getIdLong()).thenReturn(EMOTE_ID + 1);
|
||||||
emotesBag.add(emote1);
|
emotesBag.add(emote1);
|
||||||
@@ -87,7 +89,7 @@ public class EmoteTrackingListenerTest {
|
|||||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||||
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
when(messageReceivedModel.getServerId()).thenReturn(SERVER_ID);
|
||||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||||
when(message.getEmotes()).thenReturn(emotesBag);
|
when(message.getEmotesBag()).thenReturn(emotesBag);
|
||||||
testUnit.execute(messageReceivedModel);
|
testUnit.execute(messageReceivedModel);
|
||||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote1, guild, 1L);
|
||||||
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote2, guild, 1L);
|
verify(trackedEmoteService, times(1)).addEmoteToRuntimeStorage(emote2, guild, 1L);
|
||||||
@@ -95,7 +97,7 @@ public class EmoteTrackingListenerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteNoEmote() {
|
public void testExecuteNoEmote() {
|
||||||
when(message.getEmotes()).thenReturn(new ArrayList<>());
|
when(message.getEmotesBag()).thenReturn(new HashBag<>());
|
||||||
when(messageReceivedModel.getMessage()).thenReturn(message);
|
when(messageReceivedModel.getMessage()).thenReturn(message);
|
||||||
testUnit.execute(messageReceivedModel);
|
testUnit.execute(messageReceivedModel);
|
||||||
verify(trackedEmoteService, times(0)).addEmoteToRuntimeStorage(any(Emote.class), any(), anyLong());
|
verify(trackedEmoteService, times(0)).addEmoteToRuntimeStorage(any(Emote.class), any(), anyLong());
|
||||||
|
|||||||
@@ -29,12 +29,9 @@ public class UpdateTrackedEmoteListenerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmoteUpdated() {
|
public void testEmoteUpdated() {
|
||||||
Long serverId = 1L;
|
|
||||||
Long emoteId = 2L;
|
|
||||||
Emote changedEmote = Mockito.mock(Emote.class);
|
Emote changedEmote = Mockito.mock(Emote.class);
|
||||||
when(changedEmote.getIdLong()).thenReturn(emoteId);
|
|
||||||
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
TrackedEmote trackedEmote = Mockito.mock(TrackedEmote.class);
|
||||||
when(trackedEmoteManagementService.loadByEmoteId(emoteId, serverId)).thenReturn(trackedEmote);
|
when(trackedEmoteManagementService.loadByEmote(changedEmote)).thenReturn(trackedEmote);
|
||||||
String newValue = "AFTER";
|
String newValue = "AFTER";
|
||||||
when(model.getEmote()).thenReturn(changedEmote);
|
when(model.getEmote()).thenReturn(changedEmote);
|
||||||
when(model.getNewValue()).thenReturn(newValue);
|
when(model.getNewValue()).thenReturn(newValue);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.entities.MessageChannel;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -70,11 +71,15 @@ public class SuggestionManagementServiceBeanTest {
|
|||||||
when(message.getGuild()).thenReturn(guild);
|
when(message.getGuild()).thenReturn(guild);
|
||||||
when(guild.getId()).thenReturn("8");
|
when(guild.getId()).thenReturn("8");
|
||||||
long suggestionId = 1L;
|
long suggestionId = 1L;
|
||||||
|
ArgumentCaptor<Suggestion> suggestionArgumentCaptor = ArgumentCaptor.forClass(Suggestion.class);
|
||||||
|
Suggestion savedSuggestion = Mockito.mock(Suggestion.class);
|
||||||
|
when(suggestionRepository.save(suggestionArgumentCaptor.capture())).thenReturn(savedSuggestion);
|
||||||
Suggestion createdSuggestion = testUnit.createSuggestion(aUserInAServer, text, message, suggestionId);
|
Suggestion createdSuggestion = testUnit.createSuggestion(aUserInAServer, text, message, suggestionId);
|
||||||
verify(suggestionRepository, times(1)).save(createdSuggestion);
|
Assert.assertEquals(savedSuggestion, createdSuggestion);
|
||||||
Assert.assertEquals(SuggestionState.NEW, createdSuggestion.getState());
|
Suggestion capturedSuggestion = suggestionArgumentCaptor.getValue();
|
||||||
Assert.assertEquals(aUserInAServer, createdSuggestion.getSuggester());
|
Assert.assertEquals(SuggestionState.NEW, capturedSuggestion.getState());
|
||||||
Assert.assertEquals(server, createdSuggestion.getServer());
|
Assert.assertEquals(aUserInAServer, capturedSuggestion.getSuggester());
|
||||||
|
Assert.assertEquals(server, capturedSuggestion.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,11 +97,15 @@ public class SuggestionManagementServiceBeanTest {
|
|||||||
when(guild.getId()).thenReturn("5");
|
when(guild.getId()).thenReturn("5");
|
||||||
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(aUserInAServer);
|
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(aUserInAServer);
|
||||||
long suggestionId = 1L;
|
long suggestionId = 1L;
|
||||||
|
ArgumentCaptor<Suggestion> suggestionArgumentCaptor = ArgumentCaptor.forClass(Suggestion.class);
|
||||||
|
Suggestion savedSuggestion = Mockito.mock(Suggestion.class);
|
||||||
|
when(suggestionRepository.save(suggestionArgumentCaptor.capture())).thenReturn(savedSuggestion);
|
||||||
Suggestion createdSuggestion = testUnit.createSuggestion(member, text, message, suggestionId);
|
Suggestion createdSuggestion = testUnit.createSuggestion(member, text, message, suggestionId);
|
||||||
verify(suggestionRepository, times(1)).save(createdSuggestion);
|
Assert.assertEquals(savedSuggestion, createdSuggestion);
|
||||||
Assert.assertEquals(SuggestionState.NEW, createdSuggestion.getState());
|
Suggestion capturedSuggestion = suggestionArgumentCaptor.getValue();
|
||||||
Assert.assertEquals(aUserInAServer, createdSuggestion.getSuggester());
|
Assert.assertEquals(SuggestionState.NEW, capturedSuggestion.getState());
|
||||||
Assert.assertEquals(server, createdSuggestion.getServer());
|
Assert.assertEquals(aUserInAServer, capturedSuggestion.getSuggester());
|
||||||
|
Assert.assertEquals(server, capturedSuggestion.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
|||||||
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
List<String> parameters = Arrays.asList(contentStripped.split(" "));
|
||||||
UnParsedCommandParameter unParsedParameter = new UnParsedCommandParameter(contentStripped, event.getMessage());
|
UnParsedCommandParameter unParsedParameter = new UnParsedCommandParameter(contentStripped, event.getMessage());
|
||||||
String commandName = commandManager.getCommandName(parameters.get(0), event.getGuild().getIdLong());
|
String commandName = commandManager.getCommandName(parameters.get(0), event.getGuild().getIdLong());
|
||||||
foundCommand = commandManager.findCommandByParameters(commandName, unParsedParameter);
|
foundCommand = commandManager.findCommandByParameters(commandName, unParsedParameter, event.getGuild().getIdLong());
|
||||||
tryToExecuteFoundCommand(event, foundCommand, unParsedParameter);
|
tryToExecuteFoundCommand(event, foundCommand, unParsedParameter);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.config;
|
package dev.sheldan.abstracto.core.command.config;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
import dev.sheldan.abstracto.core.listener.DefaultListenerResult;
|
||||||
@@ -39,7 +39,7 @@ public class CommandConfigListenerAsync implements AsyncServerCreatedListener {
|
|||||||
if(command.getConfiguration() != null) {
|
if(command.getConfiguration() != null) {
|
||||||
ACommand aCommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
ACommand aCommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
||||||
if(!commandInServerManagementService.doesCommandExistInServer(aCommand, server)) {
|
if(!commandInServerManagementService.doesCommandExistInServer(aCommand, server)) {
|
||||||
commandInServerManagementService.crateCommandInServer(aCommand, server);
|
commandInServerManagementService.createCommandInServer(aCommand, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.command.config.features.CoreFeatureConfig;
|
|||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||||
import dev.sheldan.abstracto.core.command.models.condition.GenericConditionModel;
|
import dev.sheldan.abstracto.core.command.model.condition.GenericConditionModel;
|
||||||
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
|
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
|
||||||
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
||||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.repository;
|
package dev.sheldan.abstracto.core.command.repository;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.repository;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.CommandInServerAliasId;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CommandInServerAliasRepository extends JpaRepository<ACommandInServerAlias, CommandInServerAliasId> {
|
||||||
|
List<ACommandInServerAlias> findByCommandInAServer_ServerReference(AServer server);
|
||||||
|
Optional<ACommandInServerAlias> findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(AServer server, String name);
|
||||||
|
List<ACommandInServerAlias> findByCommandInAServer_ServerReferenceAndCommandInAServer_CommandReference_NameEqualsIgnoreCase(AServer server, String name);
|
||||||
|
boolean existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(AServer server, String name);
|
||||||
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
package dev.sheldan.abstracto.core.command.repository;
|
package dev.sheldan.abstracto.core.command.repository;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CommandInServerRepository extends JpaRepository<ACommandInAServer, Long> {
|
public interface CommandInServerRepository extends JpaRepository<ACommandInAServer, Long> {
|
||||||
|
|
||||||
ACommandInAServer findByServerReferenceAndCommandReference(AServer server, ACommand command);
|
Optional<ACommandInAServer> findByServerReferenceAndCommandReference(AServer server, ACommand command);
|
||||||
|
|
||||||
ACommandInAServer findByServerReference_IdAndCommandReference(Long serverId, ACommand command);
|
ACommandInAServer findByServerReference_IdAndCommandReference(Long serverId, ACommand command);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.repository;
|
package dev.sheldan.abstracto.core.command.repository;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.repository;
|
package dev.sheldan.abstracto.core.command.repository;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service;
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasAlreadyExistsException;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasDoesNotExistsException;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasHidesCommandException;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerAliasManagementServiceBean;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CommandInServerAliasServiceBean implements CommandInServerAliasService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasManagementServiceBean commandInServerAliasManagementServiceBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerService commandInServerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandRegistry commandRegistry;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ACommandInServerAlias createAliasForCommandInServer(Long serverId, String commandName, String alias) {
|
||||||
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
|
Optional<ACommandInServerAlias> existingAlias = commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, alias);
|
||||||
|
if(existingAlias.isPresent()) {
|
||||||
|
throw new CommandAliasAlreadyExistsException(existingAlias.get().getCommandInAServer().getCommandReference().getName());
|
||||||
|
}
|
||||||
|
Optional<Command> existingCommand = commandRegistry.getCommandByNameOptional(alias, false, serverId);
|
||||||
|
if(existingCommand.isPresent()) {
|
||||||
|
throw new CommandAliasHidesCommandException(existingCommand.get().getConfiguration().getName());
|
||||||
|
}
|
||||||
|
ACommandInAServer aCommandInAServer = commandInServerService.getCommandInAServer(server, commandName);
|
||||||
|
return commandInServerAliasManagementServiceBean.createAliasForCommand(aCommandInAServer, alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<ACommandInServerAlias> getCommandInServerAlias(Long serverId, String text) {
|
||||||
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
|
return commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCommandInServerAlias(Long serverId, String name) {
|
||||||
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
|
Optional<ACommandInServerAlias> existingAlias = commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, name);
|
||||||
|
if(existingAlias.isPresent()) {
|
||||||
|
commandInServerAliasManagementServiceBean.deleteCommandInServerAlias(existingAlias.get());
|
||||||
|
} else {
|
||||||
|
throw new CommandAliasDoesNotExistsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAliasesForCommand(Long serverId, String commandName) {
|
||||||
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
|
return commandInServerAliasManagementServiceBean.getAliasesForCommandInServer(server, commandName)
|
||||||
|
.stream().map(alias -> alias.getAliasId().getName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CommandInServerServiceBean implements CommandInServerService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandManagementService commandManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerManagementService commandInServerManagementService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ACommandInAServer getCommandInAServer(Long serverId, String name) {
|
||||||
|
AServer server = serverManagementService.loadServer(serverId);
|
||||||
|
return getCommandInAServer(server, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ACommandInAServer getCommandInAServer(AServer server, String name) {
|
||||||
|
ACommand command = commandManagementService.findCommandByName(name);
|
||||||
|
return commandInServerManagementService.getCommandForServer(command, server);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,9 +7,12 @@ import dev.sheldan.abstracto.core.command.config.ModuleDefinition;
|
|||||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
||||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -17,6 +20,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CommandManager implements CommandRegistry {
|
public class CommandManager implements CommandRegistry {
|
||||||
@@ -34,52 +38,90 @@ public class CommandManager implements CommandRegistry {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MetricService metricService;
|
private MetricService metricService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasService commandInServerAliasService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
public Command findCommandByParameters(String name, UnParsedCommandParameter unParsedCommandParameter, Long serverId) {
|
||||||
Optional<Command> commandOptional = commands.stream().filter((Command o )-> {
|
Optional<Command> commandOptional = commands.stream().filter(getCommandByNameAndParameterPredicate(name, unParsedCommandParameter)).findFirst();
|
||||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
if(!commandOptional.isPresent()) {
|
||||||
if(commandConfiguration == null) {
|
commandOptional = getCommandViaAliasAndParameter(name, unParsedCommandParameter, serverId);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if(!commandNameMatches(name, commandConfiguration)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean parameterFit;
|
|
||||||
if(commandConfiguration.getParameters() != null){
|
|
||||||
if(commandConfiguration.getNecessaryParameterCount() > unParsedCommandParameter.getParameters().size()) {
|
|
||||||
String nextParameterName = commandConfiguration.getParameters().get(commandConfiguration.getNecessaryParameterCount() - 1).getName();
|
|
||||||
metricService.incrementCounter(CommandReceivedHandler.COMMANDS_WRONG_PARAMETER_COUNTER);
|
|
||||||
throw new InsufficientParametersException(o, nextParameterName);
|
|
||||||
}
|
|
||||||
parameterFit = true;
|
|
||||||
} else {
|
|
||||||
parameterFit = unParsedCommandParameter.getParameters().isEmpty();
|
|
||||||
}
|
|
||||||
return parameterFit;
|
|
||||||
}).findFirst();
|
|
||||||
if(commandOptional.isPresent()){
|
if(commandOptional.isPresent()){
|
||||||
return commandOptional.get();
|
return commandOptional.get();
|
||||||
}
|
}
|
||||||
throw new CommandNotFoundException();
|
throw new CommandNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean commandNameMatches(String name, CommandConfiguration commandConfiguration) {
|
private Optional<Command> getCommandViaAliasAndParameter(String name, UnParsedCommandParameter unParsedCommandParameter, Long serverId) {
|
||||||
boolean commandNameMatches = commandConfiguration.getName().equalsIgnoreCase(name);
|
Optional<ACommandInServerAlias> aliasOptional = commandInServerAliasService.getCommandInServerAlias(serverId, name);
|
||||||
if(commandNameMatches) {
|
if(aliasOptional.isPresent()) {
|
||||||
return true;
|
// if its present, retrieve the original command
|
||||||
|
ACommandInAServer command = aliasOptional.get().getCommandInAServer();
|
||||||
|
// and find the command based on the newly found name
|
||||||
|
return commands.stream().filter(getCommandByNameAndParameterPredicate(command.getCommandReference().getName(), unParsedCommandParameter)).findFirst();
|
||||||
}
|
}
|
||||||
boolean aliasesMatch = false;
|
return Optional.empty();
|
||||||
if(commandConfiguration.getAliases() != null) {
|
|
||||||
aliasesMatch = commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
|
||||||
}
|
|
||||||
return aliasesMatch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command findCommand(String name) {
|
private Optional<Command> getCommandViaAlias(String name, Long serverId) {
|
||||||
|
Optional<ACommandInServerAlias> aliasOptional = commandInServerAliasService.getCommandInServerAlias(serverId, name);
|
||||||
|
if(aliasOptional.isPresent()) {
|
||||||
|
// if its present, retrieve the original command
|
||||||
|
ACommandInAServer command = aliasOptional.get().getCommandInAServer();
|
||||||
|
// and find the command based on the newly found name
|
||||||
|
return commands.stream().filter(getCommandByNamePredicate(command.getCommandReference().getName())).findFirst();
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate<Command> getCommandByNameAndParameterPredicate(String name, UnParsedCommandParameter unParsedCommandParameter) {
|
||||||
|
return (Command commandObj) -> {
|
||||||
|
CommandConfiguration commandConfiguration = commandObj.getConfiguration();
|
||||||
|
if (commandConfiguration == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!commandNameOrAliasMatches(name, commandConfiguration)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return verifyCommandConfiguration(unParsedCommandParameter, commandObj, commandConfiguration);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate<Command> getCommandByNamePredicate(String name) {
|
||||||
|
return (Command commandObj) -> {
|
||||||
|
CommandConfiguration commandConfiguration = commandObj.getConfiguration();
|
||||||
|
if (commandConfiguration == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return commandNameOrAliasMatches(name, commandConfiguration);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean verifyCommandConfiguration(UnParsedCommandParameter unParsedCommandParameter, Command command, CommandConfiguration commandConfiguration) {
|
||||||
|
if(commandConfiguration.getParameters() != null && commandConfiguration.getNecessaryParameterCount() > unParsedCommandParameter.getParameters().size()){
|
||||||
|
String nextParameterName = commandConfiguration.getParameters().get(commandConfiguration.getNecessaryParameterCount() - 1).getName();
|
||||||
|
metricService.incrementCounter(CommandReceivedHandler.COMMANDS_WRONG_PARAMETER_COUNTER);
|
||||||
|
throw new InsufficientParametersException(command, nextParameterName);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean commandNameOrAliasMatches(String name, CommandConfiguration commandConfiguration) {
|
||||||
|
return commandConfiguration.getName().equalsIgnoreCase(name) ||
|
||||||
|
commandConfiguration.getAliases() != null && commandConfiguration.getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Command findCommandViaName(String name) {
|
||||||
return commands.stream().filter((Command o )-> {
|
return commands.stream().filter((Command o )-> {
|
||||||
CommandConfiguration commandConfiguration = o.getConfiguration();
|
CommandConfiguration commandConfiguration = o.getConfiguration();
|
||||||
return commandConfiguration.getName().equals(name);
|
return commandConfiguration.getName().equalsIgnoreCase(name);
|
||||||
}).findFirst().orElseThrow(CommandNotFoundException::new);
|
}).findFirst()
|
||||||
|
.orElseThrow(CommandNotFoundException::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,22 +143,50 @@ public class CommandManager implements CommandRegistry {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommand(Message message) {
|
public boolean isCommand(Message message) {
|
||||||
return message.getContentRaw().startsWith(configService.getStringValue(PREFIX, message.getGuild().getIdLong(), getDefaultPrefix()));
|
return message.getContentRaw().startsWith(getPrefix(message.getGuild().getIdLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean commandExists(String name) {
|
public boolean commandExists(String name, boolean searchAliases, Long serverId) {
|
||||||
return commands.stream().anyMatch(command -> command.getConfiguration().getName().equalsIgnoreCase(name));
|
boolean defaultCommands = commands.stream().anyMatch(findCommandViaCommandConfig(name));
|
||||||
|
if(defaultCommands) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(searchAliases) {
|
||||||
|
return commandInServerAliasService.getCommandInServerAlias(serverId, name).isPresent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Predicate<Command> findCommandViaCommandConfig(String name) {
|
||||||
|
return command -> command.getConfiguration().getName().equalsIgnoreCase(name) || command.getConfiguration().getAliases().stream().anyMatch(s -> s.equalsIgnoreCase(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command getCommandByName(String name) {
|
public Command getCommandByName(String name, boolean searchAliases, Long serverId) {
|
||||||
return commands.stream().filter(command -> command.getConfiguration().getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
Optional<Command> defaultCommand = commands.stream().filter(findCommandViaCommandConfig(name)).findFirst();
|
||||||
|
if(defaultCommand.isPresent()) {
|
||||||
|
return defaultCommand.get();
|
||||||
|
} else {
|
||||||
|
if(searchAliases) {
|
||||||
|
return getCommandViaAlias(name, serverId).orElse(null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Command> getCommandByNameOptional(String name, boolean searchAliases, Long serverId) {
|
||||||
|
return Optional.ofNullable(getCommandByName(name, searchAliases, serverId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCommandName(String input, Long serverId) {
|
public String getCommandName(String input, Long serverId) {
|
||||||
return input.replaceFirst(configService.getStringValue(PREFIX, serverId, getDefaultPrefix()), "");
|
return input.replaceFirst(getPrefix(serverId), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPrefix(Long serverId) {
|
||||||
|
return configService.getStringValue(PREFIX, serverId, getDefaultPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDefaultPrefix() {
|
private String getDefaultPrefix() {
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
|||||||
import dev.sheldan.abstracto.core.command.config.Parameters;
|
import dev.sheldan.abstracto.core.command.config.Parameters;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||||
@@ -175,7 +175,7 @@ public class CommandServiceBean implements CommandService {
|
|||||||
public CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent) {
|
public CompletableFuture<Parameters> getParametersForCommand(String commandName, Message messageContainingContent) {
|
||||||
String contentStripped = messageContainingContent.getContentRaw();
|
String contentStripped = messageContainingContent.getContentRaw();
|
||||||
UnParsedCommandParameter unParsedParameter = getUnParsedCommandParameter(contentStripped, messageContainingContent);
|
UnParsedCommandParameter unParsedParameter = getUnParsedCommandParameter(contentStripped, messageContainingContent);
|
||||||
Command command = commandRegistry.findCommandByParameters(commandName, unParsedParameter);
|
Command command = commandRegistry.findCommandByParameters(commandName, unParsedParameter, messageContainingContent.getGuild().getIdLong());
|
||||||
return commandReceivedHandler.getParsedParameters(unParsedParameter, command, messageContainingContent);
|
return commandReceivedHandler.getParsedParameters(unParsedParameter, command, messageContainingContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.core.command.service;
|
|||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.GenericExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.GenericExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.models.FullUser;
|
import dev.sheldan.abstracto.core.models.FullUser;
|
||||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service.management;
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.repository.ChannelGroupCommandRepository;
|
import dev.sheldan.abstracto.core.command.repository.ChannelGroupCommandRepository;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.CommandInServerAliasId;
|
||||||
|
import dev.sheldan.abstracto.core.command.repository.CommandInServerAliasRepository;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CommandInServerAliasManagementServiceBean implements CommandInServerAliasManagementService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ACommandInServerAlias> getAliasesInServer(AServer server) {
|
||||||
|
return repository.findByCommandInAServer_ServerReference(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doesCommandInServerAliasExist(AServer server, String alias) {
|
||||||
|
return repository.existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<ACommandInServerAlias> getCommandInServerAlias(AServer server, String alias) {
|
||||||
|
return repository.findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ACommandInServerAlias createAliasForCommand(ACommandInAServer commandInAServer, String aliasName) {
|
||||||
|
CommandInServerAliasId identifier = CommandInServerAliasId
|
||||||
|
.builder()
|
||||||
|
.commandInServerId(commandInAServer.getCommandInServerId())
|
||||||
|
.name(aliasName)
|
||||||
|
.build();
|
||||||
|
ACommandInServerAlias alias = ACommandInServerAlias
|
||||||
|
.builder()
|
||||||
|
.commandInAServer(commandInAServer)
|
||||||
|
.aliasId(identifier)
|
||||||
|
.build();
|
||||||
|
return repository.save(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCommandInServerAlias(ACommandInServerAlias alias) {
|
||||||
|
repository.delete(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ACommandInServerAlias> getAliasesForCommandInServer(AServer server, String commandName) {
|
||||||
|
return repository.findByCommandInAServer_ServerReferenceAndCommandInAServer_CommandReference_NameEqualsIgnoreCase(server, commandName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service.management;
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.command.repository.CommandInServerRepository;
|
import dev.sheldan.abstracto.core.command.repository.CommandInServerRepository;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -17,7 +18,7 @@ public class CommandInServerManagementServiceBean implements CommandInServerMana
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ACommandInAServer crateCommandInServer(ACommand command, AServer server) {
|
public ACommandInAServer createCommandInServer(ACommand command, AServer server) {
|
||||||
ACommandInAServer commandInAServer = ACommandInAServer
|
ACommandInAServer commandInAServer = ACommandInAServer
|
||||||
.builder()
|
.builder()
|
||||||
.commandReference(command)
|
.commandReference(command)
|
||||||
@@ -30,12 +31,12 @@ public class CommandInServerManagementServiceBean implements CommandInServerMana
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doesCommandExistInServer(ACommand command, AServer server) {
|
public boolean doesCommandExistInServer(ACommand command, AServer server) {
|
||||||
return getCommandForServer(command, server) != null;
|
return repository.findByServerReferenceAndCommandReference(server, command).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ACommandInAServer getCommandForServer(ACommand command, AServer server) {
|
public ACommandInAServer getCommandForServer(ACommand command, AServer server) {
|
||||||
return repository.findByServerReferenceAndCommandReference(server, command);
|
return repository.findByServerReferenceAndCommandReference(server, command).orElseThrow(CommandNotFoundException::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service.management;
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||||
import dev.sheldan.abstracto.core.command.repository.CommandRepository;
|
import dev.sheldan.abstracto.core.command.repository.CommandRepository;
|
||||||
import dev.sheldan.abstracto.core.models.database.AFeature;
|
import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -58,4 +59,9 @@ public class CommandManagementServiceBean implements CommandManagementService {
|
|||||||
return commandRepository.existsByNameIgnoreCase(name.toLowerCase());
|
return commandRepository.existsByNameIgnoreCase(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ACommand> getAllCommands() {
|
||||||
|
return commandRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service.management;
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.AModule;
|
import dev.sheldan.abstracto.core.command.model.database.AModule;
|
||||||
import dev.sheldan.abstracto.core.command.repository.ModuleRepository;
|
import dev.sheldan.abstracto.core.command.repository.ModuleRepository;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package dev.sheldan.abstracto.core.commands.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CreateAlias extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasService aliasService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(CommandContext commandContext) {
|
||||||
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
|
String commandName = (String) parameters.get(0);
|
||||||
|
String aliasName = (String) parameters.get(1);
|
||||||
|
aliasService.createAliasForCommandInServer(commandContext.getGuild().getIdLong(), commandName, aliasName);
|
||||||
|
return CommandResult.fromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
Parameter commandNameParameter = Parameter.builder().name("commandName").type(String.class).templated(true).build();
|
||||||
|
Parameter aliasParameter = Parameter.builder().name("alias").type(String.class).templated(true).build();
|
||||||
|
List<Parameter> parameters = Arrays.asList(commandNameParameter, aliasParameter);
|
||||||
|
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name("createAlias")
|
||||||
|
.module(ConfigModuleDefinition.CONFIG)
|
||||||
|
.parameters(parameters)
|
||||||
|
.templated(true)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.help(helpInfo)
|
||||||
|
.causesReaction(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return CoreFeatureDefinition.CORE_FEATURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package dev.sheldan.abstracto.core.commands.config;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||||
|
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DeleteAlias extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasService aliasService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(CommandContext commandContext) {
|
||||||
|
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||||
|
String aliasName = (String) parameters.get(0);
|
||||||
|
aliasService.deleteCommandInServerAlias(commandContext.getGuild().getIdLong(), aliasName);
|
||||||
|
return CommandResult.fromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
Parameter aliasParameter = Parameter.builder().name("alias").type(String.class).templated(true).build();
|
||||||
|
List<Parameter> parameters = Arrays.asList(aliasParameter);
|
||||||
|
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name("deleteAlias")
|
||||||
|
.module(ConfigModuleDefinition.CONFIG)
|
||||||
|
.parameters(parameters)
|
||||||
|
.templated(true)
|
||||||
|
.supportsEmbedException(true)
|
||||||
|
.help(helpInfo)
|
||||||
|
.causesReaction(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureDefinition getFeature() {
|
||||||
|
return CoreFeatureDefinition.CORE_FEATURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
|||||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
|||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.CommandInServerAliasService;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
import dev.sheldan.abstracto.core.command.service.CommandRegistry;
|
||||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
|
import dev.sheldan.abstracto.core.command.service.ModuleRegistry;
|
||||||
@@ -30,10 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +67,9 @@ public class Help implements Command {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MetricService metricService;
|
private MetricService metricService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerAliasService commandInServerAliasService;
|
||||||
|
|
||||||
public static final String HELP_COMMAND_EXECUTED_METRIC = "help.executions";
|
public static final String HELP_COMMAND_EXECUTED_METRIC = "help.executions";
|
||||||
public static final String CATEGORY = "category";
|
public static final String CATEGORY = "category";
|
||||||
private static final CounterMetric HELP_COMMAND_NO_PARAMETER_METRIC =
|
private static final CounterMetric HELP_COMMAND_NO_PARAMETER_METRIC =
|
||||||
@@ -127,13 +128,17 @@ public class Help implements Command {
|
|||||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_module_details_response", model, commandContext.getGuild().getIdLong());
|
MessageToSend messageToSend = templateService.renderEmbedTemplate("help_module_details_response", model, commandContext.getGuild().getIdLong());
|
||||||
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
return FutureUtils.toSingleFutureGeneric(channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel()))
|
||||||
.thenApply(aVoid -> CommandResult.fromIgnored());
|
.thenApply(aVoid -> CommandResult.fromIgnored());
|
||||||
} else if(commandRegistry.commandExists(parameter)) {
|
} else {
|
||||||
|
Optional<Command> commandOptional = commandRegistry.getCommandByNameOptional(parameter, true, commandContext.getGuild().getIdLong());
|
||||||
|
if(commandOptional.isPresent()) {
|
||||||
metricService.incrementCounter(HELP_COMMAND_COMMAND_METRIC);
|
metricService.incrementCounter(HELP_COMMAND_COMMAND_METRIC);
|
||||||
Command command = commandRegistry.getCommandByName(parameter);
|
Command command = commandOptional.get();
|
||||||
log.trace("Displaying help for command {}.", command.getConfiguration().getName());
|
log.trace("Displaying help for command {}.", command.getConfiguration().getName());
|
||||||
ACommand aCommand = commandManagementService.findCommandByName(parameter);
|
ACommand aCommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
||||||
|
List<String> aliases = commandInServerAliasService.getAliasesForCommand(commandContext.getGuild().getIdLong(), command.getConfiguration().getName());
|
||||||
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getGuild().getIdLong());
|
ACommandInAServer aCommandInAServer = commandInServerManagementService.getCommandForServer(aCommand, commandContext.getGuild().getIdLong());
|
||||||
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
|
HelpCommandDetailsModel model = (HelpCommandDetailsModel) ContextConverter.fromCommandContext(commandContext, HelpCommandDetailsModel.class);
|
||||||
|
model.setServerSpecificAliases(aliases);
|
||||||
if(Boolean.TRUE.equals(aCommandInAServer.getRestricted())) {
|
if(Boolean.TRUE.equals(aCommandInAServer.getRestricted())) {
|
||||||
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
|
model.setImmuneRoles(roleService.getRolesFromGuild(aCommandInAServer.getImmuneRoles()));
|
||||||
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
|
model.setAllowedRoles(roleService.getRolesFromGuild(aCommandInAServer.getAllowedRoles()));
|
||||||
@@ -150,6 +155,7 @@ public class Help implements Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private CompletableFuture<CommandResult> displayHelpOverview(CommandContext commandContext) {
|
private CompletableFuture<CommandResult> displayHelpOverview(CommandContext commandContext) {
|
||||||
log.trace("Displaying help overview response.");
|
log.trace("Displaying help overview response.");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.service;
|
|||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.exception.ChannelGroupNotFoundException;
|
import dev.sheldan.abstracto.core.command.exception.ChannelGroupNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.service;
|
package dev.sheldan.abstracto.core.service;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||||
import dev.sheldan.abstracto.core.repository.LockRepository;
|
import dev.sheldan.abstracto.core.repository.LockRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package dev.sheldan.abstracto.core.service;
|
package dev.sheldan.abstracto.core.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
||||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||||
@@ -43,6 +46,11 @@ public class StartupServiceBean implements Startup {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RoleManagementService roleManagementService;
|
private RoleManagementService roleManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandManagementService commandManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommandInServerManagementService commandInServerManagementService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startBot() throws LoginException {
|
public void startBot() throws LoginException {
|
||||||
@@ -62,6 +70,7 @@ public class StartupServiceBean implements Startup {
|
|||||||
JDA instance = service.getInstance();
|
JDA instance = service.getInstance();
|
||||||
List<Guild> onlineGuilds = instance.getGuilds();
|
List<Guild> onlineGuilds = instance.getGuilds();
|
||||||
Set<Long> availableServers = SnowflakeUtils.getSnowflakeIds(onlineGuilds);
|
Set<Long> availableServers = SnowflakeUtils.getSnowflakeIds(onlineGuilds);
|
||||||
|
List<ACommand> existingCommands = commandManagementService.getAllCommands();
|
||||||
availableServers.forEach(aLong -> {
|
availableServers.forEach(aLong -> {
|
||||||
AServer newAServer = serverManagementService.loadOrCreate(aLong);
|
AServer newAServer = serverManagementService.loadOrCreate(aLong);
|
||||||
Guild newGuild = instance.getGuildById(aLong);
|
Guild newGuild = instance.getGuildById(aLong);
|
||||||
@@ -69,11 +78,20 @@ public class StartupServiceBean implements Startup {
|
|||||||
if(newGuild != null){
|
if(newGuild != null){
|
||||||
synchronizeRolesOf(newGuild, newAServer);
|
synchronizeRolesOf(newGuild, newAServer);
|
||||||
synchronizeChannelsOf(newGuild, newAServer);
|
synchronizeChannelsOf(newGuild, newAServer);
|
||||||
|
synchronizeCommandsInServer(newAServer, existingCommands);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void synchronizeCommandsInServer(AServer newAServer, List<ACommand> commands) {
|
||||||
|
commands.forEach(aCommand -> {
|
||||||
|
if(!commandInServerManagementService.doesCommandExistInServer(aCommand, newAServer)) {
|
||||||
|
commandInServerManagementService.createCommandInServer(aCommand, newAServer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void synchronizeRolesOf(Guild guild, AServer existingAServer){
|
private void synchronizeRolesOf(Guild guild, AServer existingAServer){
|
||||||
List<Role> guildRoles = guild.getRoles();
|
List<Role> guildRoles = guild.getRoles();
|
||||||
List<ARole> existingRoles = existingAServer.getRoles();
|
List<ARole> existingRoles = existingAServer.getRoles();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.service.management;
|
package dev.sheldan.abstracto.core.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
import dev.sheldan.abstracto.core.models.database.AChannelType;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.service.management;
|
package dev.sheldan.abstracto.core.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||||
import dev.sheldan.abstracto.core.exception.UserInServerNotFoundException;
|
import dev.sheldan.abstracto.core.exception.UserInServerNotFoundException;
|
||||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.service.management;
|
package dev.sheldan.abstracto.core.service.management;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.TableLocks;
|
import dev.sheldan.abstracto.core.command.model.TableLocks;
|
||||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||||
import dev.sheldan.abstracto.core.repository.UserRepository;
|
import dev.sheldan.abstracto.core.repository.UserRepository;
|
||||||
import dev.sheldan.abstracto.core.service.LockService;
|
import dev.sheldan.abstracto.core.service.LockService;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
|
||||||
|
<include file="core-tables/tables.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="core-seedData/data.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||||
|
<property name="coreFeature" value="(SELECT id FROM feature WHERE key = 'core')"/>
|
||||||
|
<property name="configModule" value="(SELECT id FROM module WHERE name = 'config')"/>
|
||||||
|
<changeSet author="Sheldan" id="createAlias-command" >
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="createAlias"/>
|
||||||
|
<column name="module_id" valueComputed="${configModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||||
|
</insert>
|
||||||
|
<insert tableName="command">
|
||||||
|
<column name="name" value="deleteAlias"/>
|
||||||
|
<column name="module_id" valueComputed="${configModule}"/>
|
||||||
|
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||||
|
</insert>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||||
|
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||||
|
<changeSet author="Sheldan" id="command_in_server_alias-table">
|
||||||
|
<createTable tableName="command_in_server_alias">
|
||||||
|
<column name="command_in_server_id" type="BIGINT">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="name" type="VARCHAR(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
|
||||||
|
<constraints nullable="true"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="command_in_server_id, name" tableName="command_in_server_alias" constraintName="pk_command_in_server_alias" validate="true"/>
|
||||||
|
<addForeignKeyConstraint baseColumnNames="command_in_server_id" baseTableName="command_in_server_alias" constraintName="fk_command_in_server_alias_command_in_server" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="command_in_server_id" referencedTableName="command_in_server" validate="true"/>
|
||||||
|
<sql>
|
||||||
|
DROP TRIGGER IF EXISTS command_in_server_alias_insert_trigger ON command_in_server_alias;
|
||||||
|
CREATE TRIGGER command_in_server_alias_insert_trigger BEFORE INSERT ON command_in_server_alias FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
|
||||||
|
</sql>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||||
|
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||||
|
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||||
|
<include file="command_in_server_alias.xml" relativeToChangelogFile="true"/>
|
||||||
|
</databaseChangeLog>
|
||||||
@@ -10,4 +10,5 @@
|
|||||||
<include file="1.0-templating/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.0-templating/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.1-core/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.1-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.2.5-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.service;
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||||
@@ -11,9 +11,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasAlreadyExistsException;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasDoesNotExistsException;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandAliasHidesCommandException;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.CommandInServerAliasId;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerAliasManagementServiceBean;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class CommandInServerAliasServiceBeanTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private CommandInServerAliasServiceBean testUnit;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandInServerAliasManagementServiceBean commandInServerAliasManagementServiceBean;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandInServerService commandInServerService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandRegistry commandRegistry;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AServer server;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInServerAlias alias;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInAServer aCommandInAServer;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Command command;
|
||||||
|
|
||||||
|
private static final Long SERVER_ID = 1L;
|
||||||
|
private static final String COMMAND_NAME = "command";
|
||||||
|
private static final String ALIAS_NAME = "alias";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAlias() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.empty());
|
||||||
|
when(commandRegistry.getCommandByNameOptional(ALIAS_NAME, false, SERVER_ID)).thenReturn(Optional.empty());
|
||||||
|
when(commandInServerService.getCommandInAServer(server, COMMAND_NAME)).thenReturn(aCommandInAServer);
|
||||||
|
when(commandInServerAliasManagementServiceBean.createAliasForCommand(aCommandInAServer, ALIAS_NAME)).thenReturn(alias);
|
||||||
|
ACommandInServerAlias createdAlias = testUnit.createAliasForCommandInServer(SERVER_ID, COMMAND_NAME, ALIAS_NAME);
|
||||||
|
Assert.assertEquals(alias, createdAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CommandAliasAlreadyExistsException.class)
|
||||||
|
public void testCreateAliasAlreadyExists() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.of(alias));
|
||||||
|
ACommandInAServer commandInAServer = Mockito.mock(ACommandInAServer.class);
|
||||||
|
when(alias.getCommandInAServer()).thenReturn(commandInAServer);
|
||||||
|
ACommand command = Mockito.mock(ACommand.class);
|
||||||
|
when(commandInAServer.getCommandReference()).thenReturn(command);
|
||||||
|
when(command.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
testUnit.createAliasForCommandInServer(SERVER_ID, COMMAND_NAME, ALIAS_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CommandAliasHidesCommandException.class)
|
||||||
|
public void testCreateAliasForCommandName() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.empty());
|
||||||
|
when(commandRegistry.getCommandByNameOptional(ALIAS_NAME, false, SERVER_ID)).thenReturn(Optional.of(command));
|
||||||
|
CommandConfiguration config = Mockito.mock(CommandConfiguration.class);
|
||||||
|
when(command.getConfiguration()).thenReturn(config);
|
||||||
|
when(config.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
testUnit.createAliasForCommandInServer(SERVER_ID, COMMAND_NAME, ALIAS_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInServerAliasExisting() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.of(alias));
|
||||||
|
Optional<ACommandInServerAlias> optional = testUnit.getCommandInServerAlias(SERVER_ID, ALIAS_NAME);
|
||||||
|
Assert.assertTrue(optional.isPresent());
|
||||||
|
optional.ifPresent(returnedAlias ->
|
||||||
|
Assert.assertEquals(alias, returnedAlias)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInServerAliasNotExisting() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.empty());
|
||||||
|
Optional<ACommandInServerAlias> optional = testUnit.getCommandInServerAlias(SERVER_ID, ALIAS_NAME);
|
||||||
|
Assert.assertFalse(optional.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteCommandInServerAlias() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.of(alias));
|
||||||
|
testUnit.deleteCommandInServerAlias(SERVER_ID, ALIAS_NAME);
|
||||||
|
verify(commandInServerAliasManagementServiceBean, times(1)).deleteCommandInServerAlias(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CommandAliasDoesNotExistsException.class)
|
||||||
|
public void testDeleteCommandInServerAliasNotExisting() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getCommandInServerAlias(server, ALIAS_NAME)).thenReturn(Optional.empty());
|
||||||
|
testUnit.deleteCommandInServerAlias(SERVER_ID, ALIAS_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAliasesForCommandNoResults() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getAliasesForCommandInServer(server, COMMAND_NAME)).thenReturn(new ArrayList<>());
|
||||||
|
List<String> aliases = testUnit.getAliasesForCommand(SERVER_ID, COMMAND_NAME);
|
||||||
|
Assert.assertEquals(0, aliases.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAliasesForCommandWithResults() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandInServerAliasManagementServiceBean.getAliasesForCommandInServer(server, COMMAND_NAME)).thenReturn(Arrays.asList(alias));
|
||||||
|
CommandInServerAliasId id = Mockito.mock(CommandInServerAliasId.class);
|
||||||
|
when(alias.getAliasId()).thenReturn(id);
|
||||||
|
when(id.getName()).thenReturn(ALIAS_NAME);
|
||||||
|
List<String> aliases = testUnit.getAliasesForCommand(SERVER_ID, COMMAND_NAME);
|
||||||
|
Assert.assertEquals(1, aliases.size());
|
||||||
|
Assert.assertEquals(ALIAS_NAME, aliases.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class CommandInServerServiceBeanTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private CommandInServerServiceBean testUnit;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandManagementService commandManagementService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandInServerManagementService commandInServerManagementService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AServer server;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommand command;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInAServer commandInAServer;
|
||||||
|
|
||||||
|
private static final Long SERVER_ID = 4L;
|
||||||
|
private static final String COMMAND_NAME = "command";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInAServerWithId() {
|
||||||
|
when(serverManagementService.loadServer(SERVER_ID)).thenReturn(server);
|
||||||
|
when(commandManagementService.findCommandByName(COMMAND_NAME)).thenReturn(command);
|
||||||
|
when(commandInServerManagementService.getCommandForServer(command, server)).thenReturn(commandInAServer);
|
||||||
|
ACommandInAServer foundCommandInServer = testUnit.getCommandInAServer(SERVER_ID, COMMAND_NAME);
|
||||||
|
Assert.assertEquals(commandInAServer, foundCommandInServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInAServer() {
|
||||||
|
when(commandManagementService.findCommandByName(COMMAND_NAME)).thenReturn(command);
|
||||||
|
when(commandInServerManagementService.getCommandForServer(command, server)).thenReturn(commandInAServer);
|
||||||
|
ACommandInAServer foundCommandInServer = testUnit.getCommandInAServer(server, COMMAND_NAME);
|
||||||
|
Assert.assertEquals(commandInAServer, foundCommandInServer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,337 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.ModuleDefinition;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||||
|
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
||||||
|
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.metric.service.MetricService;
|
||||||
|
import dev.sheldan.abstracto.core.models.property.SystemConfigProperty;
|
||||||
|
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||||
|
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||||
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.*;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static dev.sheldan.abstracto.core.command.service.CommandManager.PREFIX;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class CommandManagerTest {
|
||||||
|
|
||||||
|
public static final String DEFAULT_PREFIX = "!";
|
||||||
|
@InjectMocks
|
||||||
|
private CommandManager testUnit;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ConfigService configService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DefaultConfigManagementService defaultConfigManagementService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private MetricService metricService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandInServerAliasService commandInServerAliasService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ServerManagementService serverManagementService;
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
private List<Command> commands = new ArrayList<>();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Command firstCommand;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandConfiguration commandConfiguration;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private UnParsedCommandParameter parsedCommandParameter;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Parameter parameter;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInServerAlias alias;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInAServer commandInAServer;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommand aCommand;
|
||||||
|
|
||||||
|
private static final String COMMAND_NAME = "name";
|
||||||
|
private static final String COMMAND_NAME_2 = COMMAND_NAME + "suffix";
|
||||||
|
private static final String ALIAS_NAME = "name2";
|
||||||
|
private static final Long SERVER_ID = 1L;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CommandNotFoundException.class)
|
||||||
|
public void testFindByParametersNoCommands(){
|
||||||
|
when(commandInServerAliasService.getCommandInServerAlias(SERVER_ID, COMMAND_NAME)).thenReturn(Optional.empty());
|
||||||
|
testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByParametersViaCommandNameNecessaryParameter() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getNecessaryParameterCount()).thenReturn(0);
|
||||||
|
when(parsedCommandParameter.getParameters()).thenReturn(new ArrayList<>());
|
||||||
|
Command foundCommand = testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByParametersViaCommandNameNoParameters() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getParameters()).thenReturn(null);
|
||||||
|
Command foundCommand = testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByParametersViaCommandNameNoParametersButParametersGiven() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getParameters()).thenReturn(null);
|
||||||
|
Command foundCommand = testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByParametersViaCommandAliasAdequateParameter() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME_2);
|
||||||
|
when(commandConfiguration.getAliases()).thenReturn(Arrays.asList(COMMAND_NAME));
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getNecessaryParameterCount()).thenReturn(0);
|
||||||
|
when(parsedCommandParameter.getParameters()).thenReturn(new ArrayList<>());
|
||||||
|
Command foundCommand = testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = InsufficientParametersException.class)
|
||||||
|
public void testFindByParametersViaCommandNameInsufficientParameters() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getParameters()).thenReturn(Arrays.asList(parameter));
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(commandConfiguration.getNecessaryParameterCount()).thenReturn(1);
|
||||||
|
when(parsedCommandParameter.getParameters()).thenReturn(new ArrayList<>());
|
||||||
|
testUnit.findCommandByParameters(COMMAND_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindByParametersViaServerAliasAdequateParameter() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getNecessaryParameterCount()).thenReturn(0);
|
||||||
|
when(parsedCommandParameter.getParameters()).thenReturn(new ArrayList<>());
|
||||||
|
setupAliasTest();
|
||||||
|
Command foundCommand = testUnit.findCommandByParameters(ALIAS_NAME, parsedCommandParameter, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindCommandViaName() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
Command foundName = testUnit.findCommandViaName(COMMAND_NAME);
|
||||||
|
Assert.assertEquals(firstCommand, foundName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = CommandNotFoundException.class)
|
||||||
|
public void testFindCommandViaNameNotFound() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME_2);
|
||||||
|
testUnit.findCommandViaName(COMMAND_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsCommand() {
|
||||||
|
Message message = setupIsCommandScenario();
|
||||||
|
when(message.getContentRaw()).thenReturn("!com");
|
||||||
|
Assert.assertTrue(testUnit.isCommand(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsCommandNoneFound() {
|
||||||
|
Message message = setupIsCommandScenario();
|
||||||
|
when(message.getContentRaw()).thenReturn("com");
|
||||||
|
Assert.assertFalse(testUnit.isCommand(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommand() {
|
||||||
|
setupPrefix();
|
||||||
|
String foundCommandName = testUnit.getCommandName("!com", SERVER_ID);
|
||||||
|
Assert.assertEquals("com", foundCommandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandByNameWithoutAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Command foundCommand = testUnit.getCommandByName(COMMAND_NAME, false, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandByNameOptionalWithoutAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Optional<Command> foundCommandOptional = testUnit.getCommandByNameOptional(COMMAND_NAME, false, SERVER_ID);
|
||||||
|
Assert.assertTrue(foundCommandOptional.isPresent());
|
||||||
|
foundCommandOptional.ifPresent(command -> {
|
||||||
|
Assert.assertEquals(firstCommand, foundCommandOptional.get());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandByNameNotFoundWithoutAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME_2);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Command foundCommand = testUnit.getCommandByName(COMMAND_NAME, false, SERVER_ID);
|
||||||
|
Assert.assertNull(foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandByNameViaAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
setupAliasTest();
|
||||||
|
Command foundCommand = testUnit.getCommandByName(ALIAS_NAME, true, SERVER_ID);
|
||||||
|
Assert.assertEquals(firstCommand, foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandByNameViaAliasNotFound() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Command foundCommand = testUnit.getCommandByName(ALIAS_NAME, true, SERVER_ID);
|
||||||
|
Assert.assertNull(foundCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandExistsWithoutAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Assert.assertTrue(testUnit.commandExists(COMMAND_NAME, false, SERVER_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandExistsWithoutAliasNotFound() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME_2);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
Assert.assertFalse(testUnit.commandExists(COMMAND_NAME, false, SERVER_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandExistsWithAlias() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
setupAliasTest();
|
||||||
|
Assert.assertTrue(testUnit.commandExists(COMMAND_NAME, true, SERVER_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommandExistsWithAliasNotFound() {
|
||||||
|
commands.add(firstCommand);
|
||||||
|
when(commandConfiguration.getName()).thenReturn(COMMAND_NAME_2);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
setupAliasTest();
|
||||||
|
Assert.assertFalse(testUnit.commandExists(COMMAND_NAME, true, SERVER_ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllCommandsFromModuleOneCommandFound() {
|
||||||
|
ModuleDefinition moduleDefinition = Mockito.mock(ModuleDefinition.class);
|
||||||
|
ModuleInfo info = Mockito.mock(ModuleInfo.class);
|
||||||
|
String moduleName = "module";
|
||||||
|
when(info.getName()).thenReturn(moduleName);
|
||||||
|
when(moduleDefinition.getInfo()).thenReturn(info);
|
||||||
|
when(commandConfiguration.getModule()).thenReturn(moduleName);
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
commands.add(firstCommand);
|
||||||
|
List<Command> foundCommands = testUnit.getAllCommandsFromModule(moduleDefinition);
|
||||||
|
Assert.assertEquals(1, foundCommands.size());
|
||||||
|
Assert.assertEquals(firstCommand, foundCommands.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllCommandsFromModuleNoCommandFound() {
|
||||||
|
ModuleDefinition moduleDefinition = Mockito.mock(ModuleDefinition.class);
|
||||||
|
ModuleInfo info = Mockito.mock(ModuleInfo.class);
|
||||||
|
String moduleName = "module";
|
||||||
|
when(info.getName()).thenReturn(moduleName);
|
||||||
|
when(moduleDefinition.getInfo()).thenReturn(info);
|
||||||
|
when(commandConfiguration.getModule()).thenReturn(moduleName + "2");
|
||||||
|
when(firstCommand.getConfiguration()).thenReturn(commandConfiguration);
|
||||||
|
commands.add(firstCommand);
|
||||||
|
List<Command> foundCommands = testUnit.getAllCommandsFromModule(moduleDefinition);
|
||||||
|
Assert.assertEquals(0, foundCommands.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setupAliasTest() {
|
||||||
|
when(commandInServerAliasService.getCommandInServerAlias(SERVER_ID, ALIAS_NAME)).thenReturn(Optional.of(alias));
|
||||||
|
when(alias.getCommandInAServer()).thenReturn(commandInAServer);
|
||||||
|
when(commandInAServer.getCommandReference()).thenReturn(aCommand);
|
||||||
|
when(aCommand.getName()).thenReturn(COMMAND_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Message setupIsCommandScenario() {
|
||||||
|
Message message = Mockito.mock(Message.class);
|
||||||
|
setupPrefix();
|
||||||
|
Guild guild = Mockito.mock(Guild.class);
|
||||||
|
when(message.getGuild()).thenReturn(guild);
|
||||||
|
when(guild.getIdLong()).thenReturn(SERVER_ID);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupPrefix() {
|
||||||
|
SystemConfigProperty defaultConfig = Mockito.mock(SystemConfigProperty.class);
|
||||||
|
when(defaultConfig.getStringValue()).thenReturn(DEFAULT_PREFIX);
|
||||||
|
when(defaultConfigManagementService.getDefaultConfig(PREFIX)).thenReturn(defaultConfig);
|
||||||
|
when(configService.getStringValue(PREFIX, SERVER_ID, DEFAULT_PREFIX)).thenReturn(DEFAULT_PREFIX);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.service.management;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInServerAlias;
|
||||||
|
import dev.sheldan.abstracto.core.command.repository.CommandInServerAliasRepository;
|
||||||
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
|
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;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class CommandInServerAliasManagementServiceBeanTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private CommandInServerAliasManagementServiceBean testUnit;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private CommandInServerAliasRepository repository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ACommandInServerAlias alias;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AServer server;
|
||||||
|
|
||||||
|
private static final String ALIAS_NAME = "alias";
|
||||||
|
private static final String COMMAND_NAME = "command";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAliasesInServer() {
|
||||||
|
when(repository.findByCommandInAServer_ServerReference(server)).thenReturn(Arrays.asList(alias));
|
||||||
|
List<ACommandInServerAlias> foundAliases = testUnit.getAliasesInServer(server);
|
||||||
|
Assert.assertEquals(1, foundAliases.size());
|
||||||
|
Assert.assertEquals(alias, foundAliases.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoesCommandInServerAliasExist() {
|
||||||
|
when(repository.existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, ALIAS_NAME)).thenReturn(true);
|
||||||
|
Assert.assertTrue(testUnit.doesCommandInServerAliasExist(server, ALIAS_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoesCommandInServerAliasNotExist() {
|
||||||
|
when(repository.existsByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, ALIAS_NAME)).thenReturn(false);
|
||||||
|
Assert.assertFalse(testUnit.doesCommandInServerAliasExist(server, ALIAS_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInServerAlias() {
|
||||||
|
when(repository.findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, ALIAS_NAME)).thenReturn(Optional.of(alias));
|
||||||
|
Optional<ACommandInServerAlias> commandOptional = testUnit.getCommandInServerAlias(server, ALIAS_NAME);
|
||||||
|
Assert.assertTrue(commandOptional.isPresent());
|
||||||
|
commandOptional.ifPresent(existingAlias ->
|
||||||
|
Assert.assertEquals(alias, existingAlias)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCommandInServerAliasNotExist() {
|
||||||
|
when(repository.findByCommandInAServer_ServerReferenceAndAliasId_NameEqualsIgnoreCase(server, ALIAS_NAME)).thenReturn(Optional.empty());
|
||||||
|
Optional<ACommandInServerAlias> commandOptional = testUnit.getCommandInServerAlias(server, ALIAS_NAME);
|
||||||
|
Assert.assertFalse(commandOptional.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateAliasForCommand() {
|
||||||
|
ACommandInAServer commandInAServer = Mockito.mock(ACommandInAServer.class);
|
||||||
|
ArgumentCaptor<ACommandInServerAlias> aliasArgumentCaptor = ArgumentCaptor.forClass(ACommandInServerAlias.class);
|
||||||
|
ACommandInServerAlias savedAlias = Mockito.mock(ACommandInServerAlias.class);
|
||||||
|
when(repository.save(aliasArgumentCaptor.capture())).thenReturn(savedAlias);
|
||||||
|
ACommandInServerAlias createdAlias = testUnit.createAliasForCommand(commandInAServer, ALIAS_NAME);
|
||||||
|
Assert.assertEquals(savedAlias, createdAlias);
|
||||||
|
ACommandInServerAlias capturedAlias = aliasArgumentCaptor.getValue();
|
||||||
|
Assert.assertEquals(commandInAServer, capturedAlias.getCommandInAServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteCommandInServerAlias() {
|
||||||
|
testUnit.deleteCommandInServerAlias(alias);
|
||||||
|
verify(repository, times(1)).delete(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAliasesForCommandInServer() {
|
||||||
|
when(repository.findByCommandInAServer_ServerReferenceAndCommandInAServer_CommandReference_NameEqualsIgnoreCase(server, COMMAND_NAME)).thenReturn(Arrays.asList(alias));
|
||||||
|
List<ACommandInServerAlias> foundAliases = testUnit.getAliasesForCommandInServer(server, COMMAND_NAME);
|
||||||
|
Assert.assertEquals(1, foundAliases.size());
|
||||||
|
Assert.assertEquals(alias, foundAliases.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -67,11 +68,13 @@ public class AllowedMentionManagementServiceBeanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void createCustomAllowedMention() {
|
public void createCustomAllowedMention() {
|
||||||
when(serverManagementService.loadOrCreate(SERVER_ID)).thenReturn(server);
|
when(serverManagementService.loadOrCreate(SERVER_ID)).thenReturn(server);
|
||||||
AllowedMention createdMention = testUnit.createCustomAllowedMention(SERVER_ID, allowedMention);
|
|
||||||
ArgumentCaptor<AllowedMention> mentionCaptor = ArgumentCaptor.forClass(AllowedMention.class);
|
ArgumentCaptor<AllowedMention> mentionCaptor = ArgumentCaptor.forClass(AllowedMention.class);
|
||||||
verify(allowedMentionRepository, times(1)).save(mentionCaptor.capture());
|
AllowedMention toReturn = Mockito.mock(AllowedMention.class);
|
||||||
Assert.assertEquals(createdMention, mentionCaptor.getValue());
|
when(allowedMentionRepository.save(mentionCaptor.capture())).thenReturn(toReturn);
|
||||||
Assert.assertEquals(server, createdMention.getServer());
|
AllowedMention createdMention = testUnit.createCustomAllowedMention(SERVER_ID, allowedMention);
|
||||||
|
Assert.assertEquals(toReturn, createdMention);
|
||||||
|
AllowedMention usedValue = mentionCaptor.getValue();
|
||||||
|
Assert.assertEquals(server, usedValue.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import dev.sheldan.abstracto.core.repository.FeatureModeRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
@@ -43,29 +45,36 @@ public class FeatureModeManagementServiceBeanTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private AFeatureMode aFeatureMode;
|
private AFeatureMode aFeatureMode;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<AFeatureMode> modeCaptor;
|
||||||
|
|
||||||
private static final String FEATURE_MODE = "featureMode";
|
private static final String FEATURE_MODE = "featureMode";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createModeWithModeAsString() {
|
public void createModeWithModeAsString() {
|
||||||
when(featureFlag.getServer()).thenReturn(server);
|
when(featureFlag.getServer()).thenReturn(server);
|
||||||
|
when(featureModeRepository.save(modeCaptor.capture())).thenReturn(aFeatureMode);
|
||||||
AFeatureMode createdMode = testUnit.createMode(featureFlag, FEATURE_MODE, true);
|
AFeatureMode createdMode = testUnit.createMode(featureFlag, FEATURE_MODE, true);
|
||||||
Assert.assertEquals(true, createdMode.getEnabled());
|
AFeatureMode createdValue = modeCaptor.getValue();
|
||||||
Assert.assertEquals(featureFlag, createdMode.getFeatureFlag());
|
Assert.assertEquals(aFeatureMode, createdMode);
|
||||||
Assert.assertEquals(FEATURE_MODE, createdMode.getFeatureMode());
|
Assert.assertEquals(true, createdValue.getEnabled());
|
||||||
Assert.assertEquals(server, createdMode.getServer());
|
Assert.assertEquals(featureFlag, createdValue.getFeatureFlag());
|
||||||
verify(featureModeRepository, times(1)).save(createdMode);
|
Assert.assertEquals(FEATURE_MODE, createdValue.getFeatureMode());
|
||||||
|
Assert.assertEquals(server, createdValue.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateMode() {
|
public void testCreateMode() {
|
||||||
when(featureFlag.getServer()).thenReturn(server);
|
when(featureFlag.getServer()).thenReturn(server);
|
||||||
when(featureMode.getKey()).thenReturn(FEATURE_MODE);
|
when(featureMode.getKey()).thenReturn(FEATURE_MODE);
|
||||||
|
when(featureModeRepository.save(modeCaptor.capture())).thenReturn(aFeatureMode);
|
||||||
AFeatureMode createdMode = testUnit.createMode(featureFlag, featureMode, true);
|
AFeatureMode createdMode = testUnit.createMode(featureFlag, featureMode, true);
|
||||||
Assert.assertEquals(true, createdMode.getEnabled());
|
AFeatureMode createdValue = modeCaptor.getValue();
|
||||||
Assert.assertEquals(featureFlag, createdMode.getFeatureFlag());
|
Assert.assertEquals(aFeatureMode, createdMode);
|
||||||
Assert.assertEquals(FEATURE_MODE, createdMode.getFeatureMode());
|
Assert.assertEquals(true, createdValue.getEnabled());
|
||||||
Assert.assertEquals(server, createdMode.getServer());
|
Assert.assertEquals(featureFlag, createdValue.getFeatureFlag());
|
||||||
verify(featureModeRepository, times(1)).save(createdMode);
|
Assert.assertEquals(FEATURE_MODE, createdValue.getFeatureMode());
|
||||||
|
Assert.assertEquals(server, createdValue.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import dev.sheldan.abstracto.core.templating.repository.TemplateRepository;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
@@ -24,6 +26,12 @@ public class TemplateManagementServiceBeanTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TemplateRepository repository;
|
private TemplateRepository repository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Template template;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Template> templateArgumentCaptor;
|
||||||
|
|
||||||
private static final String TEMPLATE_KEY = "templateKey";
|
private static final String TEMPLATE_KEY = "templateKey";
|
||||||
private static final String TEMPLATE_SOURCE = "source";
|
private static final String TEMPLATE_SOURCE = "source";
|
||||||
|
|
||||||
@@ -53,11 +61,14 @@ public class TemplateManagementServiceBeanTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTemplate() {
|
public void testCreateTemplate() {
|
||||||
Template template = templateManagementServiceBean.createTemplate(TEMPLATE_KEY, TEMPLATE_SOURCE);
|
when(repository.save(templateArgumentCaptor.capture())).thenReturn(template);
|
||||||
Assert.assertEquals(template.getContent(), TEMPLATE_SOURCE);
|
Template createdTemplate = templateManagementServiceBean.createTemplate(TEMPLATE_KEY, TEMPLATE_SOURCE);
|
||||||
Assert.assertEquals(template.getKey(), TEMPLATE_KEY);
|
Template savedTemplate = templateArgumentCaptor.getValue();
|
||||||
|
Assert.assertEquals(template, createdTemplate);
|
||||||
|
Assert.assertEquals(TEMPLATE_SOURCE, savedTemplate.getContent());
|
||||||
|
Assert.assertEquals(TEMPLATE_KEY, savedTemplate.getKey());
|
||||||
verify(repository, times(1)).save(any(Template.class));
|
verify(repository, times(1)).save(any(Template.class));
|
||||||
Assert.assertTrue(Duration.between(template.getLastModified(), Instant.now()).getSeconds() < 1);
|
Assert.assertTrue(Duration.between(savedTemplate.getLastModified(), Instant.now()).getSeconds() < 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Template getTemplate() {
|
private Template getTemplate() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.core.command.condition;
|
|||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.condition.detail.CommandDisabledDetail;
|
import dev.sheldan.abstracto.core.command.condition.detail.CommandDisabledDetail;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.service.ChannelGroupCommandService;
|
import dev.sheldan.abstracto.core.command.service.ChannelGroupCommandService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package dev.sheldan.abstracto.core.command.condition;
|
|||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.condition.detail.InsufficientPermissionConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.detail.InsufficientPermissionConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package dev.sheldan.abstracto.core.command.condition;
|
|||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.condition.detail.ImmuneUserConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.detail.ImmuneUserConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
import dev.sheldan.abstracto.core.command.model.database.ACommand;
|
||||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
import dev.sheldan.abstracto.core.command.model.database.ACommandInAServer;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.condition.detail;
|
package dev.sheldan.abstracto.core.command.condition.detail;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.command.models.condition.FeatureDisabledConditionDetailModel;
|
import dev.sheldan.abstracto.core.command.model.condition.FeatureDisabledConditionDetailModel;
|
||||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.condition.detail;
|
package dev.sheldan.abstracto.core.command.condition.detail;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.command.models.condition.ImmuneUserConditionDetailModel;
|
import dev.sheldan.abstracto.core.command.model.condition.ImmuneUserConditionDetailModel;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
|
||||||
public class ImmuneUserConditionDetail implements ConditionDetail {
|
public class ImmuneUserConditionDetail implements ConditionDetail {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.condition.detail;
|
package dev.sheldan.abstracto.core.command.condition.detail;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.command.models.condition.InsufficientPermissionCondtionDetailModel;
|
import dev.sheldan.abstracto.core.command.model.condition.InsufficientPermissionCondtionDetailModel;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelAlreadyInChannelGroupExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.ChannelAlreadyInChannelGroupExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupExistsExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.ChannelGroupExistsExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupIncorrectTypeExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.ChannelGroupIncorrectTypeExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupNotFoundExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.ChannelGroupNotFoundExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelNotInChannelGroupExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.ChannelNotInChannelGroupExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.exception.CommandAliasAlreadyExistsModel;
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
public class CommandAliasAlreadyExistsException extends AbstractoRunTimeException implements Templatable {
|
||||||
|
|
||||||
|
private final CommandAliasAlreadyExistsModel model;
|
||||||
|
|
||||||
|
public CommandAliasAlreadyExistsException(String existingCommand) {
|
||||||
|
this.model = CommandAliasAlreadyExistsModel
|
||||||
|
.builder()
|
||||||
|
.existingCommand(existingCommand)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
return "command_in_server_alias_already_exists_exception";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTemplateModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CommandAliasDoesNotExistsException extends AbstractoRunTimeException implements Templatable {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
return "command_in_server_alias_not_exists_exists_exception";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTemplateModel() {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.model.exception.CommandAliasHidesCommandModel;
|
||||||
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
public class CommandAliasHidesCommandException extends AbstractoRunTimeException implements Templatable {
|
||||||
|
|
||||||
|
private final CommandAliasHidesCommandModel model;
|
||||||
|
|
||||||
|
public CommandAliasHidesCommandException(String existingCommand) {
|
||||||
|
this.model = CommandAliasHidesCommandModel
|
||||||
|
.builder()
|
||||||
|
.existingCommand(existingCommand)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
return "command_in_server_alias_hides_command_exception";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getTemplateModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.CommandParameterKeyValueWrongTypeExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.CommandParameterKeyValueWrongTypeExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.command.exception;
|
|||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||||
import dev.sheldan.abstracto.core.command.config.validator.ValidatorParam;
|
import dev.sheldan.abstracto.core.command.config.validator.ValidatorParam;
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.CommandParameterValidationExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.CommandParameterValidationExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.IncorrectParameterExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.IncorrectParameterExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.sheldan.abstracto.core.command.exception;
|
package dev.sheldan.abstracto.core.command.exception;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.Command;
|
import dev.sheldan.abstracto.core.command.Command;
|
||||||
import dev.sheldan.abstracto.core.command.models.exception.InsufficientParametersExceptionModel;
|
import dev.sheldan.abstracto.core.command.model.exception.InsufficientParametersExceptionModel;
|
||||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models;
|
package dev.sheldan.abstracto.core.command.model;
|
||||||
|
|
||||||
public enum TableLocks {
|
public enum TableLocks {
|
||||||
CHANNELS, USER_IN_SERVER, USER
|
CHANNELS, USER_IN_SERVER, USER
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.condition;
|
package dev.sheldan.abstracto.core.command.model.condition;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.condition;
|
package dev.sheldan.abstracto.core.command.model.condition;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
import dev.sheldan.abstracto.core.command.condition.ConditionDetail;
|
||||||
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.condition;
|
package dev.sheldan.abstracto.core.command.model.condition;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.condition;
|
package dev.sheldan.abstracto.core.command.model.condition;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.database;
|
package dev.sheldan.abstracto.core.command.model.database;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||||
import dev.sheldan.abstracto.core.models.database.AFeature;
|
import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dev.sheldan.abstracto.core.command.models.database;
|
package dev.sheldan.abstracto.core.command.model.database;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||||
@@ -47,6 +47,9 @@ public class ACommandInAServer implements Serializable {
|
|||||||
@Getter
|
@Getter
|
||||||
private List<ARole> immuneRoles;
|
private List<ARole> immuneRoles;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "commandInAServer", fetch = FetchType.LAZY)
|
||||||
|
private List<ACommandInServerAlias> aliases;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Column(name = "restricted")
|
@Column(name = "restricted")
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.sheldan.abstracto.core.command.model.database;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@Entity(name = "command_in_server_alias")
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class ACommandInServerAlias implements Serializable {
|
||||||
|
|
||||||
|
@EmbeddedId
|
||||||
|
private CommandInServerAliasId aliasId;
|
||||||
|
|
||||||
|
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||||
|
@MapsId("commandInServerId")
|
||||||
|
@JoinColumn(name = "command_in_server_id", referencedColumnName = "command_in_server_id", nullable = false)
|
||||||
|
private ACommandInAServer commandInAServer;
|
||||||
|
|
||||||
|
@Column(name = "created")
|
||||||
|
private Instant created;
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user