Search in sources :

Example 16 with Broker

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);
    }
}
Also used : TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) File(java.io.File) Before(org.junit.Before)

Example 17 with Broker

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());
}
Also used : Path(java.nio.file.Path) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) SSLContext(javax.net.ssl.SSLContext) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Before(org.junit.Before)

Example 18 with Broker

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();
}
Also used : Broker(org.apache.qpid.server.model.Broker) ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) EventLogger(org.apache.qpid.server.logging.EventLogger) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) Principal(java.security.Principal) AccessControl(org.apache.qpid.server.security.AccessControl) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl) Before(org.junit.Before)

Example 19 with Broker

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;
}
Also used : Broker(org.apache.qpid.server.model.Broker)

Example 20 with Broker

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")));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Broker(org.apache.qpid.server.model.Broker) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Aggregations

Broker (org.apache.qpid.server.model.Broker)38 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)15 EventLogger (org.apache.qpid.server.logging.EventLogger)13 Before (org.junit.Before)11 Test (org.junit.Test)8 Subject (javax.security.auth.Subject)7 HashMap (java.util.HashMap)6 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)6 VirtualHost (org.apache.qpid.server.model.VirtualHost)6 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)6 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)5 Model (org.apache.qpid.server.model.Model)5 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)4 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AccessControlException (java.security.AccessControlException)3 Principal (java.security.Principal)3 SSLContext (javax.net.ssl.SSLContext)3 BrokerModel (org.apache.qpid.server.model.BrokerModel)3 Queue (org.apache.qpid.server.model.Queue)3