mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-08 02:17:43 +00:00
[AB-207] fixing command being disabled, if its part of a channel group, but the given channel is not part of that channel group
fixing null pointer in channel group created listener fixing connection string in config deploy tool
This commit is contained in:
@@ -33,9 +33,13 @@ public class ChannelGroupCommandServiceBean implements ChannelGroupCommandServic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// empty -> no groups, command enabled
|
||||
// not empty -> has groups, command is disabled in all
|
||||
return allChannelGroupsOfCommand.isEmpty();
|
||||
/*
|
||||
if we are here this means either:
|
||||
the command has no channel groups assigned -> enabled
|
||||
the command has one or more channel group and is enabled in these ones -> enabled
|
||||
the command has a channel group with channels (and it might be enabled/disabled, does not matter), but the given channel is not part of that group -> ok
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ public class AsyncChannelGroupCreatedListenerManager {
|
||||
|
||||
@TransactionalEventListener
|
||||
public void executeListener(ChannelGroupCreatedListenerModel createdGroup){
|
||||
if(listener == null) return;
|
||||
listener.forEach(asyncChannelGroupCreatedListener ->
|
||||
listenerService.executeListener(asyncChannelGroupCreatedListener, createdGroup, channelGroupCreatedExecutor)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.management.ChannelGroupCommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroupCommand;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChannelGroupCommandServiceBeanTest {
|
||||
|
||||
@InjectMocks
|
||||
private ChannelGroupCommandServiceBean testUnit;
|
||||
|
||||
@Mock
|
||||
private ChannelGroupCommandManagementService channelGroupCommandService;
|
||||
|
||||
@Mock
|
||||
private ChannelManagementService channelManagementService;
|
||||
|
||||
@Mock
|
||||
private ACommand command;
|
||||
|
||||
@Mock
|
||||
private AChannel channel;
|
||||
|
||||
@Mock
|
||||
private AChannel secondChannel;
|
||||
|
||||
@Mock
|
||||
private AChannelGroupCommand channelGroupCommand;
|
||||
|
||||
@Mock
|
||||
private AChannelGroup channelGroup;
|
||||
|
||||
private static final Long CHANNEL_ID = 4L;
|
||||
private static final Long CHANNEL_ID_2 = 2L;
|
||||
|
||||
@Test
|
||||
public void testNoChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(new ArrayList<>());
|
||||
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneDisabledChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
|
||||
when(channelGroupCommand.getEnabled()).thenReturn(false);
|
||||
Assert.assertFalse(testUnit.isCommandEnabled(command, channel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneEnabledChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
|
||||
when(channelGroupCommand.getEnabled()).thenReturn(true);
|
||||
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabledInOneGroupChannelIsNotPartOf() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(secondChannel));
|
||||
when(channel.getId()).thenReturn(CHANNEL_ID);
|
||||
when(secondChannel.getId()).thenReturn(CHANNEL_ID_2);
|
||||
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy.sql import text
|
||||
|
||||
|
||||
def deploy_template_folder(db_config, folder):
|
||||
engine = db.create_engine('postgres://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
|
||||
engine = db.create_engine('postgresql://%s:%s@%s:%s/%s' % (db_config.user, db_config.password, db_config.host, db_config.port, db_config.database))
|
||||
|
||||
if not os.path.isdir(folder):
|
||||
print("Given path was not a folder. Exiting.")
|
||||
|
||||
Reference in New Issue
Block a user