use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class ConnectionVersionValidatorTest method setUp.
@Before
public void setUp() throws Exception {
_connectionValidator = new ConnectionVersionValidator();
_virtualHostMock = mock(QueueManagingVirtualHost.class);
_connectionMock = mock(AMQPConnection.class);
_eventLoggerMock = mock(EventLogger.class);
Broker brokerMock = mock(Broker.class);
when(_virtualHostMock.getBroker()).thenReturn(brokerMock);
when(brokerMock.getEventLogger()).thenReturn(_eventLoggerMock);
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class ServerConnectionDelegateTest method setUp.
@Before
public void setUp() {
_taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
final Broker broker = mock(Broker.class);
when(broker.getNetworkBufferSize()).thenReturn(0xffff);
when(broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(Long.MAX_VALUE);
when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(broker.getModel()).thenReturn(BrokerModel.getInstance());
final AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
when(authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(Collections.singletonList("PLAIN"));
final AmqpPort<?> port = mock(AmqpPort.class);
when(port.getAuthenticationProvider()).thenReturn(authenticationProvider);
when(port.getParent()).thenReturn(broker);
_delegate = new ServerConnectionDelegate(port, true, "test");
_delegate.setState(ServerConnectionDelegate.ConnectionState.OPEN);
final NamedAddressSpace addressSpace = mock(NamedAddressSpace.class);
when(addressSpace.getConnections()).thenReturn(Collections.emptyList());
final Subject subject = new Subject();
subject.setReadOnly();
_accessControlContext = AccessController.getContext();
final AMQPConnection_0_10 amqpConnection = mock(AMQPConnection_0_10.class);
when(amqpConnection.getParent()).thenReturn(broker);
when(amqpConnection.getBroker()).thenReturn(broker);
when(amqpConnection.getChildExecutor()).thenReturn(_taskExecutor);
when(amqpConnection.getModel()).thenReturn(BrokerModel.getInstance());
when(amqpConnection.getSubject()).thenReturn(subject);
when(amqpConnection.getContextValue(Long.class, org.apache.qpid.server.model.Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Long.MAX_VALUE);
when(amqpConnection.getContextValue(Integer.class, org.apache.qpid.server.model.Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Integer.MAX_VALUE);
doAnswer((Answer<AccessControlContext>) invocationOnMock -> {
Subject subject1 = (Subject) invocationOnMock.getArgument(0);
return AccessController.doPrivileged((PrivilegedAction<AccessControlContext>) () -> new AccessControlContext(_accessControlContext, new SubjectDomainCombiner(subject1)));
}).when(amqpConnection).getAccessControlContextFromSubject(any());
when(amqpConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
_serverConnection = mock(ServerConnection.class);
when(_serverConnection.getAddressSpace()).thenReturn(addressSpace);
when(_serverConnection.getBroker()).thenReturn(broker);
when(_serverConnection.getAmqpConnection()).thenReturn(amqpConnection);
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class VirtualHostLoggerTest method setUp.
@Before
public void setUp() throws Exception {
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
Model model = BrokerModel.getInstance();
EventLogger eventLogger = mock(EventLogger.class);
SystemConfig<?> systemConfig = mock(SystemConfig.class);
when(systemConfig.getModel()).thenReturn(model);
when(systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
when(systemConfig.getEventLogger()).thenReturn(eventLogger);
when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControlMock = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControlMock);
when(broker.getModel()).thenReturn(model);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
when(broker.getParent()).thenReturn(systemConfig);
doReturn(Broker.class).when(broker).getCategoryClass();
VirtualHostNode node = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControlMock);
when(node.getModel()).thenReturn(model);
when(node.getChildExecutor()).thenReturn(_taskExecutor);
when(node.getParent()).thenReturn(broker);
when(node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
doReturn(VirtualHostNode.class).when(node).getCategoryClass();
when(node.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
// use real VH object rather then mock in order to test create/start/stop functionality
Map<String, Object> attributes = new HashMap<>();
attributes.put(VirtualHost.NAME, getTestName());
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
_virtualHost = new TestMemoryVirtualHost(attributes, node);
_virtualHost.open();
_baseFolder = new File(TMP_FOLDER, "test-sub-folder");
_logFile = new File(_baseFolder, "tmp-virtual-host.log." + System.currentTimeMillis());
if (_baseFolder.exists()) {
FileUtils.delete(_baseFolder, true);
}
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class JDBCVirtualHostNodeTest method testInvalidTableNamePrefix.
@Test
public void testInvalidTableNamePrefix() throws Exception {
SystemConfig systemConfig = mock(SystemConfig.class);
Broker broker = mock(Broker.class);
final ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
when(broker.getObjectFactory()).thenReturn(factory);
when(broker.getModel()).thenReturn(factory.getModel());
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
when(broker.getParent()).thenReturn(systemConfig);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, getTestName());
attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
attributes.put("connectionUrl", "jdbc://example.com");
JDBCVirtualHostNode<?> jdbcVirtualHostNode = new JDBCVirtualHostNodeImpl(attributes, broker);
// This list is not exhaustive
List<String> knownInvalidPrefixes = Arrays.asList("with\"dblquote", "with'quote", "with-dash", "with;semicolon", "with space", "with%percent", "with|pipe", "with(paren", "with)paren", "with[bracket", "with]bracket", "with{brace", "with}brace");
for (String invalidPrefix : knownInvalidPrefixes) {
try {
jdbcVirtualHostNode.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
} catch (IllegalConfigurationException e) {
// pass
}
}
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class BrokerMemoryLoggerTest method doMemoryLoggerLimitsTest.
private void doMemoryLoggerLimitsTest(final int illegalValue, final int legalValue) {
final String brokerLoggerName = "TestBrokerLogger";
Broker broker = _systemConfig.getContainer(Broker.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, brokerLoggerName);
attributes.put(ConfiguredObject.TYPE, BrokerMemoryLogger.TYPE);
attributes.put(BrokerMemoryLogger.MAX_RECORDS, illegalValue);
try {
broker.createChild(BrokerLogger.class, attributes);
fail("Exception not thrown");
} catch (IllegalConfigurationException ice) {
// PASS
}
attributes.put(BrokerMemoryLogger.MAX_RECORDS, legalValue);
BrokerLogger brokerLogger = (BrokerLogger) broker.createChild(BrokerLogger.class, attributes);
try {
brokerLogger.setAttributes(Collections.singletonMap(BrokerMemoryLogger.MAX_RECORDS, illegalValue));
fail("Exception not thrown");
} catch (IllegalConfigurationException ice) {
// PASS
} finally {
brokerLogger.delete();
}
}
Aggregations