PropertiesChangedListenerTest.java 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */

18
package org.apache.shardingsphere.governance.core.config.listener;
19

L
Liang Zhang 已提交
20 21
import org.apache.shardingsphere.governance.core.event.model.GovernanceEvent;
import org.apache.shardingsphere.governance.core.event.model.props.PropertiesChangedEvent;
22 23
import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
kimmking's avatar
kimmking 已提交
24
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent.Type;
K
kimmking 已提交
25
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
26 27 28 29 30 31
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

32 33
import java.util.Optional;

34 35
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
36
import static org.junit.Assert.assertTrue;
37 38 39 40

@RunWith(MockitoJUnitRunner.class)
public final class PropertiesChangedListenerTest {
    
K
kimmking 已提交
41
    private static final String PROPERTIES_YAML = ConfigurationPropertyKey.ACCEPTOR_SIZE.getKey() + ": 16\n" + ConfigurationPropertyKey.SQL_SHOW.getKey() + ": true";
42 43 44 45
    
    private PropertiesChangedListener propertiesChangedListener;
    
    @Mock
46
    private ConfigurationRepository configurationRepository;
47 48 49
    
    @Before
    public void setUp() {
M
menghaoranss 已提交
50
        propertiesChangedListener = new PropertiesChangedListener(configurationRepository);
51 52 53
    }
    
    @Test
54
    public void assertCreateGovernanceEvent() {
kimmking's avatar
kimmking 已提交
55
        Optional<GovernanceEvent> actual = propertiesChangedListener.createGovernanceEvent(new DataChangedEvent("test", PROPERTIES_YAML, Type.UPDATED));
56
        assertTrue(actual.isPresent());
K
kimmking 已提交
57 58
        assertThat(((PropertiesChangedEvent) actual.get()).getProps().get(ConfigurationPropertyKey.SQL_SHOW.getKey()), is(true));
        assertThat(((PropertiesChangedEvent) actual.get()).getProps().get(ConfigurationPropertyKey.ACCEPTOR_SIZE.getKey()), is(16));
59 60
    }
}