use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class BrokerFileLoggerTest 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);
doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
_broker = mock(Broker.class);
when(_broker.getModel()).thenReturn(model);
when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
when(_broker.getParent()).thenReturn(systemConfig);
doReturn(Broker.class).when(_broker).getCategoryClass();
_baseFolder = new File(TMP_FOLDER, "test-sub-folder");
_logFile = new File(_baseFolder, "tmp-broker-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 OAuth2AuthenticationProviderImplTest method setUp.
@Before
public void setUp() throws Exception {
Path keyStore = TLS_RESOURCE.createSelfSignedKeyStore("CN=foo");
_server = new OAuth2MockEndpointHolder(keyStore.toFile().getAbsolutePath(), TLS_RESOURCE.getSecret(), TLS_RESOURCE.getKeyStoreType());
_server.start();
Broker broker = BrokerTestHelper.createBrokerMock();
TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
when(broker.getTaskExecutor()).thenReturn(taskExecutor);
when(broker.getChildExecutor()).thenReturn(taskExecutor);
final Map<String, Object> authProviderAttributes = new HashMap<>();
authProviderAttributes.put(ConfiguredObject.NAME, "testOAuthProvider");
authProviderAttributes.put("clientId", TEST_CLIENT_ID);
authProviderAttributes.put("clientSecret", TEST_CLIENT_SECRET);
authProviderAttributes.put("identityResolverType", TEST_IDENTITY_RESOLVER_TYPE);
authProviderAttributes.put("authorizationEndpointURI", String.format(TEST_AUTHORIZATION_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_AUTHORIZATION_ENDPOINT_PATH));
authProviderAttributes.put("tokenEndpointURI", String.format(TEST_TOKEN_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_TOKEN_ENDPOINT_PATH));
authProviderAttributes.put("tokenEndpointNeedsAuth", TEST_AUTHORIZATION_ENDPOINT_NEEDS_AUTH);
authProviderAttributes.put("identityResolverEndpointURI", String.format(TEST_IDENTITY_RESOLVER_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_IDENTITY_RESOLVER_ENDPOINT_PATH));
authProviderAttributes.put("postLogoutURI", String.format(TEST_POST_LOGOUT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_POST_LOGOUT_PATH));
authProviderAttributes.put("scope", TEST_SCOPE);
authProviderAttributes.put("trustStore", TEST_TRUST_STORE_NAME);
setTestSystemProperty(CachingAuthenticationProvider.AUTHENTICATION_CACHE_MAX_SIZE, "0");
_authProvider = new OAuth2AuthenticationProviderImpl(authProviderAttributes, broker);
_authProvider.open();
assertEquals("Could not successfully open authProvider", State.ACTIVE, _authProvider.getState());
final TrustManager[] trustingTrustManager = new TrustManager[] { new TrustingTrustManager() };
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustingTrustManager, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new BlindHostnameVerifier());
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class VirtualHostQueueCreationTest method setUp.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setUp() throws Exception {
EventLogger eventLogger = mock(EventLogger.class);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
_taskExecutor = new CurrentThreadTaskExecutor();
_taskExecutor.start();
SystemConfig<?> context = mock(SystemConfig.class);
when(context.getEventLogger()).thenReturn(eventLogger);
when(context.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControl = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControl);
when(broker.getObjectFactory()).thenReturn(objectFactory);
when(broker.getCategoryClass()).thenReturn(Broker.class);
when(broker.getParent()).thenReturn(context);
when(broker.getModel()).thenReturn(objectFactory.getModel());
when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
_virtualHostNode = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControl);
when(_virtualHostNode.getParent()).thenReturn(broker);
when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(_virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(_virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
_virtualHost = createHost();
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class LatestManagementControllerAdapterTest method createTestVirtualHost.
private QueueManagingVirtualHost<?> createTestVirtualHost(final String hostName) throws Exception {
final QueueManagingVirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost(hostName, this);
final Broker root = virtualHost.getBroker();
final ConfiguredObject<?> virtualHostNode = virtualHost.getParent();
when(root.getChildren(VirtualHostNode.class)).thenReturn(Collections.singletonList(virtualHostNode));
when(virtualHostNode.getChildren(VirtualHost.class)).thenReturn(Collections.singletonList(virtualHost));
when(virtualHostNode.getChildByName(VirtualHost.class, hostName)).thenReturn(virtualHost);
return virtualHost;
}
use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.
the class LatestManagementControllerAdapterTest method handlePost.
@Test
public void handlePost() throws Exception {
final String hostName = "test";
final String queueName = "foo";
final QueueManagingVirtualHost<?> virtualHost = createTestVirtualHost(hostName);
final String nodeName = virtualHost.getParent().getName();
final Broker root = virtualHost.getBroker();
final ManagementRequest request = mockManagementRequest(root, "POST", "queue", Arrays.asList(nodeName, hostName), Collections.emptyMap());
when(request.getBody(LinkedHashMap.class)).thenReturn(new LinkedHashMap<String, Object>(Collections.singletonMap("name", queueName)));
when(request.getRequestURL()).thenReturn("test");
final ManagementResponse response = _adapter.handlePut(request);
assertThat(response, is(notNullValue()));
assertThat(response.getResponseCode(), is(equalTo(201)));
assertThat(response.getBody(), is(notNullValue()));
assertThat(response.getBody(), is(instanceOf(LegacyConfiguredObject.class)));
final LegacyConfiguredObject object = (LegacyConfiguredObject) response.getBody();
assertThat(object.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("foo")));
}
Aggregations