Fix some test cases

This commit is contained in:
Wu Sheng 2018-07-19 22:52:33 +08:00
parent e05b99a936
commit e7ec6dcc31
14 changed files with 123 additions and 203 deletions

View File

@ -0,0 +1,43 @@
/*
* 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.skywalking.oap.server.library.module;
import org.junit.Assert;
import org.junit.Test;
import java.util.Properties;
public class ApplicationConfigurationTest {
@Test
public void testBuildConfig() {
ApplicationConfiguration configuration = new ApplicationConfiguration();
Properties p1 = new Properties();
p1.setProperty("p1", "value1");
p1.setProperty("p2", "value2");
Properties p2 = new Properties();
p2.setProperty("prop1", "value1-prop");
p2.setProperty("prop2", "value2-prop");
configuration.addModule("MO-1").addProviderConfiguration("MO-1-P1", p1).addProviderConfiguration("MO-1-P2", p2);
Assert.assertArrayEquals(new String[] {"MO-1"}, configuration.moduleList());
Assert.assertEquals("value2-prop", configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P2").getProperty("prop2"));
Assert.assertEquals(p1, configuration.getModuleConfiguration("MO-1").getProviderConfiguration("MO-1-P1"));
}
}

View File

@ -1,56 +0,0 @@
/*
* 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.skywalking.oap.server.library.module;
import java.util.Properties;
import org.junit.*;
/**
* @author peng-yongsheng
*/
public class ApplicationConfigurationTestCase {
@Test
public void test() {
ApplicationConfiguration configuration = new ApplicationConfiguration();
Properties providerAConfig = new Properties();
providerAConfig.setProperty("A-key1", "A-value1");
providerAConfig.setProperty("A-key2", "A-value2");
Properties providerBConfig = new Properties();
providerBConfig.setProperty("B-key1", "B-value1");
providerBConfig.setProperty("B-key2", "B-value2");
final String module = "Module";
final String providerA = "ProviderA";
final String providerB = "ProviderB";
configuration.addModule(module)
.addProviderConfiguration(providerA, providerAConfig)
.addProviderConfiguration(providerB, providerBConfig);
Assert.assertArrayEquals(new String[] {module}, configuration.moduleList());
Assert.assertTrue(configuration.has(module));
Assert.assertFalse(configuration.has("ModuleB"));
Assert.assertTrue(configuration.getModuleConfiguration(module).has(providerA));
Assert.assertFalse(configuration.getModuleConfiguration(module).has("ProviderC"));
Assert.assertEquals("B-value1", configuration.getModuleConfiguration(module).getProviderConfiguration(providerB).getProperty("B-key1"));
Assert.assertEquals(providerAConfig, configuration.getModuleConfiguration(module).getProviderConfiguration(providerA));
}
}

View File

@ -16,28 +16,26 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng, peng-yongsheng
* @author wu-sheng
*/
public class BaseModuleA extends ModuleDefine {
static final String NAME = "BaseModuleA";
@Override public String name() {
return NAME;
return "BaseA";
}
@Override public Class[] services() {
@Override public Class<? extends Service>[] services() {
return new Class[] {ServiceABusiness1.class, ServiceABusiness2.class};
}
public interface ServiceABusiness1 {
public interface ServiceABusiness1 extends Service {
void print();
}
public interface ServiceABusiness2 {
public interface ServiceABusiness2 extends Service {
}
}

View File

@ -16,28 +16,26 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng
*/
public class BaseModuleB extends ModuleDefine {
static final String NAME = "BaseModuleB";
@Override public String name() {
return NAME;
return "BaseB";
}
@Override public Class[] services() {
@Override public Class<? extends Service>[] services() {
return new Class[] {BaseModuleB.ServiceBBusiness1.class, BaseModuleB.ServiceBBusiness2.class};
}
public interface ServiceBBusiness1 {
public interface ServiceBBusiness1 extends Service {
}
public interface ServiceBBusiness2 {
public interface ServiceBBusiness2 extends Service {
}
}

View File

@ -16,6 +16,7 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**

View File

@ -16,6 +16,7 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**

View File

@ -19,23 +19,15 @@
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng, peng-yongsheng
* @author wu-sheng
*/
public class ModuleAProvider extends ModuleProvider {
static final String NAME = "ModuleAProvider";
private ModuleConfig config;
@Override public String name() {
return NAME;
return "P-A";
}
@Override public ModuleConfig createConfigBeanIfAbsent() {
if (config == null) {
config = new Config();
}
return config;
return null;
}
@Override public Class<? extends ModuleDefine> module() {
@ -53,11 +45,10 @@ public class ModuleAProvider extends ModuleProvider {
@Override public void notifyAfterCompleted() {
}
public class Config {
private String host;
@Override public String[] requiredModules() {
return new String[0];
}
public String getHost() {
return host;
}
class Config {
}
}

View File

@ -16,6 +16,7 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**

View File

@ -16,6 +16,7 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**

View File

@ -19,14 +19,12 @@
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng, peng-yongsheng
* @author wu-sheng
*/
public class ModuleBProvider extends ModuleProvider {
static final String NAME = "ModuleBProvider";
@Override public String name() {
return NAME;
return "P-B";
}
@Override public ModuleConfig createConfigBeanIfAbsent() {
@ -48,6 +46,10 @@ public class ModuleBProvider extends ModuleProvider {
@Override public void notifyAfterCompleted() {
}
@Override public String[] requiredModules() {
return new String[0];
}
class Config {
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.skywalking.oap.server.library.module;
import org.junit.Assert;
import org.junit.Test;
import java.util.Properties;
/**
* @author wu-sheng
*/
public class ModuleManagerTest {
@Test
public void testInit() throws ServiceNotProvidedException, ModuleNotFoundException, ProviderNotFoundException, DuplicateProviderException, ModuleConfigException, ModuleStartException {
ApplicationConfiguration configuration = new ApplicationConfiguration();
configuration.addModule("Test").addProviderConfiguration("TestModule-Provider", new Properties());
configuration.addModule("BaseA").addProviderConfiguration("P-A", new Properties());
configuration.addModule("BaseB").addProviderConfiguration("P-B", new Properties());
ModuleManager manager = new ModuleManager();
manager.init(configuration);
BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find("BaseA").provider().getService(BaseModuleA.ServiceABusiness1.class);
Assert.assertTrue(serviceABusiness1 != null);
}
}

View File

@ -1,102 +0,0 @@
/*
* 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.skywalking.oap.server.library.module;
import java.util.Properties;
import org.junit.*;
/**
* @author peng-yongsheng
*/
public class ModuleManagerTestCase {
private ApplicationConfiguration configuration;
@Before
public void init() {
Properties providerAConfig = new Properties();
providerAConfig.setProperty("host", "oap");
providerAConfig.setProperty("A-key1", "A-value1");
providerAConfig.setProperty("A-key2", "A-value2");
configuration = new ApplicationConfiguration();
configuration.addModule(TestModule.NAME).addProviderConfiguration(TestModuleProvider.NAME, new Properties());
configuration.addModule(BaseModuleA.NAME).addProviderConfiguration(ModuleAProvider.NAME, providerAConfig);
configuration.addModule(BaseModuleB.NAME).addProviderConfiguration(ModuleBProvider.NAME, new Properties());
}
@Test
public void testHas() throws ModuleNotFoundException, ModuleConfigException, ServiceNotProvidedException, ProviderNotFoundException, ModuleStartException, DuplicateProviderException {
// ModuleManager manager = new ModuleManager();
// manager.init(configuration);
//
// Assert.assertTrue(manager.has(TestModule.NAME));
// Assert.assertTrue(manager.has(BaseModuleA.NAME));
// Assert.assertTrue(manager.has(BaseModuleB.NAME));
//
// Assert.assertFalse(manager.has("Undefined"));
}
@Test
public void testFind() throws ModuleNotFoundException, ModuleConfigException, ServiceNotProvidedException, ProviderNotFoundException, ModuleStartException, DuplicateProviderException {
// ModuleManager manager = new ModuleManager();
// manager.init(configuration);
//
// try {
// manager.find("Undefined");
// } catch (ModuleNotFoundRuntimeException e) {
// Assert.assertEquals("Undefined missing.", e.getMessage());
// }
}
@Test
public void testInit() throws ServiceNotProvidedException, DuplicateProviderException, ModuleConfigException, ModuleNotFoundException, ProviderNotFoundException, ModuleStartException {
// ModuleManager manager = new ModuleManager();
// manager.init(configuration);
// BaseModuleA.ServiceABusiness1 serviceABusiness1 = manager.find(BaseModuleA.NAME).provider().getService(BaseModuleA.ServiceABusiness1.class);
// Assert.assertNotNull(serviceABusiness1);
//
// ModuleAProvider.Config config = (ModuleAProvider.Config)manager.find(BaseModuleA.NAME).provider().createConfigBeanIfAbsent();
// Assert.assertEquals("oap", config.getHost());
}
@Test
public void testAssertPreparedStage() {
// ModuleManager manager = new ModuleManager();
//
// try {
// manager.find("Undefined");
// } catch (AssertionError e) {
// Assert.assertEquals("Still in preparing stage.", e.getMessage());
// }
}
@Test
public void testEmptyConfig() throws ModuleConfigException, ServiceNotProvidedException, ProviderNotFoundException, ModuleStartException, DuplicateProviderException {
// configuration.addModule("Undefined").addProviderConfiguration("Undefined", new Properties());
//
// ModuleManager manager = new ModuleManager();
//
// try {
// manager.init(configuration);
// } catch (ModuleNotFoundException e) {
// Assert.assertEquals("[Undefined] missing.", e.getMessage());
// }
}
}

View File

@ -16,20 +16,18 @@
*
*/
package org.apache.skywalking.oap.server.library.module;
/**
* @author wu-sheng, peng-yongsheng
* @author wu-sheng
*/
public class TestModule extends ModuleDefine {
static final String NAME = "TestModule";
@Override public String name() {
return NAME;
return "Test";
}
@Override public Class[] services() {
@Override public Class<? extends Service>[] services() {
return new Class[0];
}
}

View File

@ -22,11 +22,8 @@ package org.apache.skywalking.oap.server.library.module;
* @author wu-sheng
*/
public class TestModuleProvider extends ModuleProvider {
static final String NAME = "TestModuleProvider";
@Override public String name() {
return NAME;
return "TestModule-Provider";
}
@Override public Class<? extends ModuleDefine> module() {
@ -46,6 +43,10 @@ public class TestModuleProvider extends ModuleProvider {
@Override public void notifyAfterCompleted() {
}
@Override public String[] requiredModules() {
return new String[] {"BaseA", "BaseB"};
}
class Config {
}
}