Skip to content

Commit 431d3c9

Browse files
author
kongming
committed
add unit testcase for propertiesProviders
1 parent e5b0dea commit 431d3c9

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/config/PropertiesConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public PropertiesConfiguration(String prefix, String id) {
3434
super(prefix, id);
3535

3636
ExtensionLoader<OrderedPropertiesProvider> propertiesProviderExtensionLoader = ExtensionLoader.getExtensionLoader(OrderedPropertiesProvider.class);
37-
Set<String> propertiesProviderNames = propertiesProviderExtensionLoader.getLoadedExtensions();
38-
if (propertiesProviderNames == null) {
37+
Set<String> propertiesProviderNames = propertiesProviderExtensionLoader.getSupportedExtensions();
38+
if (propertiesProviderNames == null || propertiesProviderNames.isEmpty()) {
3939
return;
4040
}
4141
List<OrderedPropertiesProvider> orderedPropertiesProviders = new ArrayList<>();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.config;
18+
19+
import java.util.Properties;
20+
21+
public class MockOrderedPropertiesProvider1 implements OrderedPropertiesProvider {
22+
@Override
23+
public int priority() {
24+
return 3;
25+
}
26+
27+
@Override
28+
public Properties initProperties() {
29+
Properties properties = new Properties();
30+
properties.put("testKey", "333");
31+
return properties;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.config;
18+
19+
import java.util.Properties;
20+
21+
public class MockOrderedPropertiesProvider2 implements OrderedPropertiesProvider {
22+
@Override
23+
public int priority() {
24+
return 1;
25+
}
26+
27+
@Override
28+
public Properties initProperties() {
29+
Properties properties = new Properties();
30+
properties.put("testKey", "999");
31+
return properties;
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.config;
18+
19+
import org.junit.Assert;
20+
import org.junit.Test;
21+
22+
public class PropertiesConfigurationTest {
23+
24+
@Test
25+
public void testOrderPropertiesProviders() {
26+
PropertiesConfiguration configuration = new PropertiesConfiguration("test", null);
27+
Assert.assertTrue(configuration.getInternalProperty("testKey").equals("999"));
28+
}
29+
30+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mock1=org.apache.dubbo.common.config.MockOrderedPropertiesProvider1
2+
mock2=org.apache.dubbo.common.config.MockOrderedPropertiesProvider2

0 commit comments

Comments
 (0)