Skip to content

Commit

Permalink
add unit testcase for propertiesProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
kongming committed Feb 25, 2019
1 parent e5b0dea commit 431d3c9
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public PropertiesConfiguration(String prefix, String id) {
super(prefix, id);

ExtensionLoader<OrderedPropertiesProvider> propertiesProviderExtensionLoader = ExtensionLoader.getExtensionLoader(OrderedPropertiesProvider.class);
Set<String> propertiesProviderNames = propertiesProviderExtensionLoader.getLoadedExtensions();
if (propertiesProviderNames == null) {
Set<String> propertiesProviderNames = propertiesProviderExtensionLoader.getSupportedExtensions();
if (propertiesProviderNames == null || propertiesProviderNames.isEmpty()) {
return;
}
List<OrderedPropertiesProvider> orderedPropertiesProviders = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.dubbo.common.config;

import java.util.Properties;

public class MockOrderedPropertiesProvider1 implements OrderedPropertiesProvider {
@Override
public int priority() {
return 3;
}

@Override
public Properties initProperties() {
Properties properties = new Properties();
properties.put("testKey", "333");
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.dubbo.common.config;

import java.util.Properties;

public class MockOrderedPropertiesProvider2 implements OrderedPropertiesProvider {
@Override
public int priority() {
return 1;
}

@Override
public Properties initProperties() {
Properties properties = new Properties();
properties.put("testKey", "999");
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.dubbo.common.config;

import org.junit.Assert;
import org.junit.Test;

public class PropertiesConfigurationTest {

@Test
public void testOrderPropertiesProviders() {
PropertiesConfiguration configuration = new PropertiesConfiguration("test", null);
Assert.assertTrue(configuration.getInternalProperty("testKey").equals("999"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mock1=org.apache.dubbo.common.config.MockOrderedPropertiesProvider1
mock2=org.apache.dubbo.common.config.MockOrderedPropertiesProvider2

0 comments on commit 431d3c9

Please sign in to comment.