summaryrefslogtreecommitdiff
path: root/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
blob: 257f1398495a5867a37c5e34c7f1fd4017a7ad3c (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * 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 java.io.Reader;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.qpid.disttest.ConfigFileTestHelper;
import org.apache.qpid.disttest.client.property.PropertyValue;

public class ConfigReaderTest extends TestCase
{
    private Config _config;

    @Override
    protected void setUp()
    {
        ConfigReader configReader = new ConfigReader();
        Reader reader = ConfigFileTestHelper.getConfigFileReader(getClass(), "sampleConfig.json");
        _config = configReader.readConfig(reader);
    }

    public void testReadTest()
    {
        List<TestConfig> tests = _config.getTestConfigs();
        assertEquals("Unexpected number of tests", 2, tests.size());
        TestConfig test1Config = tests.get(0);
        assertNotNull("Test 1 configuration is expected", test1Config);
        assertEquals("Unexpected test name", "Test 1", test1Config.getName());

        TestConfig test2Config = tests.get(1);
        assertNotNull("Test 2 configuration is expected", test2Config);
    }

    public void testReadsTestWithQueues()
    {
        TestConfig test1Config =  _config.getTestConfigs().get(0);
        List<QueueConfig> queues = test1Config.getQueues();
        assertEquals("Unexpected number of queues", 2, queues.size());
        QueueConfig queue1Config = queues.get(0);
        assertNotNull("Expected queue 1 config", queue1Config);
        assertEquals("Unexpected queue name", "Json-Queue-Name", queue1Config.getName());
        assertTrue("Unexpected attributes", queue1Config.getAttributes().isEmpty());
        assertFalse("Unexpected durable", queue1Config.isDurable());

        QueueConfig queue2Config = queues.get(1);
        assertNotNull("Expected queue 2 config", queue2Config);
        assertEquals("Unexpected queue name", "Json Queue Name 2", queue2Config.getName());
        assertTrue("Unexpected durable", queue2Config.isDurable());
        Map<String, Object> attributes =  queue2Config.getAttributes();
        assertNotNull("Expected attributes", attributes);
        assertFalse("Attributes are not loaded", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 1, attributes.size());
        assertEquals("Unexpected attribute 'x-qpid-priorities' value", 10,
                ((Number)attributes.get("x-qpid-priorities")).intValue());
    }

    public void testReadsTestWithIterations()
    {
        TestConfig testConfig = _config.getTestConfigs().get(0);
        List<IterationValue> iterationValues = testConfig.getIterationValues();
        assertEquals("Unexpected number of iterations", 2, iterationValues.size());

        IterationValue iteration1 = iterationValues.get(0);

        String messageSizeProperty = "_messageSize";

        assertEquals("Unexpected value for property " + messageSizeProperty,
                "100",
                iteration1.getIterationPropertyValuesWithUnderscores().get(messageSizeProperty));
    }

    public void testReadsMessageProviders()
    {
        TestConfig testConfig = _config.getTestConfigs().get(0);
        ClientConfig cleintConfig = testConfig.getClients().get(0);
        List<MessageProviderConfig> configs = cleintConfig.getMessageProviders();
        assertNotNull("Message provider configs should not be null", configs);
        assertEquals("Unexpected number of message providers", 1, configs.size());
        MessageProviderConfig messageProvider = configs.get(0);
        assertNotNull("Message provider config should not be null", messageProvider);
        assertEquals("Unexpected provider name", "testProvider1", messageProvider.getName());
        Map<String, PropertyValue> properties = messageProvider.getMessageProperties();
        assertNotNull("Message properties should not be null", properties);
        assertEquals("Unexpected number of message properties", 3, properties.size());
        assertNotNull("test property is not found", properties.get("test"));
        assertNotNull("priority property is not found", properties.get("priority"));
        assertNotNull("id property is not found", properties.get("id"));
     }

    public void testReadsJS() throws Exception
    {
        ConfigReader configReader = new ConfigReader();
        String path = getClass().getResource("ConfigReaderTest-test-config.js").toURI().getPath();
        _config = configReader.getConfigFromFile(path);
        List<TestConfig> testConfigs = _config.getTestConfigs();
        assertEquals("Unexpected number of tests", 2, testConfigs.size());
        TestConfig testConfig1 = _config.getTestConfigs().get(0);
        List<ClientConfig> cleintConfigs = testConfig1.getClients();
        assertEquals("Unexpected number of test 1 clients", 2, cleintConfigs.size());
        List<QueueConfig> queueConfigs = testConfig1.getQueues();
        assertEquals("Unexpected number of test 1 queue", 1, queueConfigs.size());
        assertEquals("Unexpected queue name", "Json-Queue-Name", queueConfigs.get(0).getName());
        ClientConfig cleintConfig = cleintConfigs.get(0);
        List<ConnectionConfig> connectionConfigs = cleintConfig.getConnections();
        assertEquals("Unexpected number of connections", 1, connectionConfigs.size());
        List<SessionConfig> sessionConfigs = connectionConfigs.get(0).getSessions();
        assertEquals("Unexpected number of sessions", 1, sessionConfigs.size());
        assertEquals("Unexpected ack mode", 0, sessionConfigs.get(0).getAcknowledgeMode());

        TestConfig testConfig2 = _config.getTestConfigs().get(1);
        List<ClientConfig> cleintConfigs2 = testConfig2.getClients();
        assertEquals("Unexpected number of test 1 clients", 2, cleintConfigs2.size());
        List<QueueConfig> queueConfigs2 = testConfig2.getQueues();
        assertEquals("Unexpected number of test 1 queue", 1, queueConfigs2.size());
        assertEquals("Unexpected queue name", "Json-Queue-Name", queueConfigs2.get(0).getName());
        ClientConfig cleintConfig2 = cleintConfigs2.get(0);
        List<ConnectionConfig> connectionConfigs2 = cleintConfig2.getConnections();
        assertEquals("Unexpected number of connections", 1, connectionConfigs2.size());
        List<SessionConfig> sessionConfigs2 = connectionConfigs2.get(0).getSessions();
        assertEquals("Unexpected number of sessions", 1, sessionConfigs2.size());
        assertEquals("Unexpected ack mode", 1, sessionConfigs2.get(0).getAcknowledgeMode());
    }

}