summaryrefslogtreecommitdiff
path: root/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementTest.java
blob: 52d7ba33a3b135d9c42a7aa2738e6af63408caa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.server.management.plugin;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.BrokerModel;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl;
import org.apache.qpid.server.model.State;
import org.apache.qpid.test.utils.QpidTestCase;

public class HttpManagementTest extends QpidTestCase
{
    private UUID _id;
    private Broker _broker;
    private HttpManagement _management;

    @Override
    public void setUp() throws Exception
    {
        super.setUp();
        _id = UUID.randomUUID();
        _broker = mock(Broker.class);
        ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());

        when(_broker.getObjectFactory()).thenReturn(objectFactory);
        when(_broker.getModel()).thenReturn(objectFactory.getModel());
        when(_broker.getCategoryClass()).thenReturn(Broker.class);
        when(_broker.getEventLogger()).thenReturn(mock(EventLogger.class));
        when(_broker.getTaskExecutor()).thenReturn(mock(TaskExecutor.class));

        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false);
        attributes.put(HttpManagement.HTTPS_BASIC_AUTHENTICATION_ENABLED, true);
        attributes.put(HttpManagement.HTTP_SASL_AUTHENTICATION_ENABLED, false);
        attributes.put(HttpManagement.HTTPS_SASL_AUTHENTICATION_ENABLED, true);
        attributes.put(HttpManagement.NAME, getTestName());
        attributes.put(HttpManagement.TIME_OUT, 10000l);
        attributes.put(ConfiguredObject.ID, _id);
        attributes.put(HttpManagement.DESIRED_STATE, State.QUIESCED);
        _management = new HttpManagement(attributes, _broker);
        _management.open();
    }

    public void testGetSessionTimeout()
    {
        assertEquals("Unexpected session timeout", 10000l, _management.getSessionTimeout());
    }

    public void testGetName()
    {
        assertEquals("Unexpected name", getTestName(), _management.getName());
    }

    public void testIsHttpsSaslAuthenticationEnabled()
    {
        assertEquals("Unexpected value for the https sasl enabled attribute", true,
                _management.isHttpsSaslAuthenticationEnabled());
    }

    public void testIsHttpSaslAuthenticationEnabled()
    {
        assertEquals("Unexpected value for the http sasl enabled attribute", false, _management.isHttpSaslAuthenticationEnabled());
    }

    public void testIsHttpsBasicAuthenticationEnabled()
    {
        assertEquals("Unexpected value for the https basic authentication enabled attribute", true,
                _management.isHttpsBasicAuthenticationEnabled());
    }

    public void testIsHttpBasicAuthenticationEnabled()
    {
        assertEquals("Unexpected value for the http basic authentication enabled attribute", false,
                _management.isHttpBasicAuthenticationEnabled());
    }

    public void testGetAuthenticationProvider()
    {
        SocketAddress localAddress = InetSocketAddress.createUnresolved("localhost", 8080);
        AuthenticationProvider brokerAuthenticationProvider = mock(AuthenticationProvider.class);
        when(_broker.getAuthenticationProvider(localAddress)).thenReturn(brokerAuthenticationProvider);
        AuthenticationProvider authenticationProvider = _management.getAuthenticationProvider(localAddress);
        assertEquals("Unexpected subject creator", brokerAuthenticationProvider, authenticationProvider);
    }

}