summaryrefslogtreecommitdiff
path: root/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ClientConfigTest.java
blob: 4bf4307eaf17fc5bf03b8438ce5c895042488ecb (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
/*
 * 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.disttest.controller.config;

import static org.apache.qpid.disttest.controller.config.ConfigTestUtils.assertCommandForClient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.qpid.disttest.client.property.PropertyValue;
import org.apache.qpid.disttest.client.property.SimplePropertyValue;
import org.apache.qpid.disttest.controller.CommandForClient;
import org.apache.qpid.disttest.message.Command;
import org.apache.qpid.disttest.message.CreateMessageProviderCommand;
import org.apache.qpid.disttest.message.NoOpCommand;
import org.apache.qpid.test.utils.QpidTestCase;

public class ClientConfigTest extends QpidTestCase
{
    private static final String CLIENT1 = "client1";

    public void testClientConfigHasZeroArgConstructorForGson()
    {
        ClientConfig c = new ClientConfig();
        assertNotNull(c);
    }

    public void testCreateCommands()
    {
        ClientConfig clientConfig = createClientConfigWithConnectionConfigReturningChildCommands();

        List<CommandForClient> commands = clientConfig.createCommands();
        assertEquals(2, commands.size());

        assertCommandForClient(commands, 0, CLIENT1, NoOpCommand.class);
        assertCommandForClient(commands, 1, CLIENT1, NoOpCommand.class);
    }

    public void testCreateCommandsForMessageProvider()
    {
        ClientConfig clientConfig = createClientConfigWithMessageProviderConfigReturningCommands();

        List<CommandForClient> commands = clientConfig.createCommands();
        assertEquals(1, commands.size());

        assertCommandForClient(commands, 0, CLIENT1, CreateMessageProviderCommand.class);
    }

    public void testGetTotalNumberOfParticipants()
    {
        ClientConfig clientConfig = createClientConfigWithTwoParticipants();
        assertEquals(2, clientConfig.getTotalNumberOfParticipants());
    }

    private ClientConfig createClientConfigWithConnectionConfigReturningChildCommands()
    {
        ConnectionConfig connectionConfig = mock(ConnectionConfig.class);

        List<Command> commands = Arrays.asList((Command)new NoOpCommand(), (Command)new NoOpCommand());
        when(connectionConfig.createCommands()).thenReturn(commands);

        return new ClientConfig(CLIENT1, connectionConfig);
    }

    private ClientConfig createClientConfigWithMessageProviderConfigReturningCommands()
    {
        Map<String, PropertyValue> messageProperties = new HashMap<String, PropertyValue>();
        messageProperties.put("test", new SimplePropertyValue("testValue"));
        MessageProviderConfig config = new MessageProviderConfig("test", messageProperties);

        List<MessageProviderConfig> providerConfigs = new ArrayList<MessageProviderConfig>();
        providerConfigs.add(config);

        return new ClientConfig(CLIENT1, new ArrayList<ConnectionConfig>(), providerConfigs);
    }

    private ClientConfig createClientConfigWithTwoParticipants()
    {
        ConnectionConfig connectionConfig1 = mock(ConnectionConfig.class);
        ConnectionConfig connectionConfig2 = mock(ConnectionConfig.class);

        when(connectionConfig1.getTotalNumberOfParticipants()).thenReturn(1);
        when(connectionConfig2.getTotalNumberOfParticipants()).thenReturn(1);

        ClientConfig clientConfig = new ClientConfig(CLIENT1, connectionConfig1, connectionConfig2);
        return clientConfig;
    }
}