diff options
author | 2017-08-08 14:02:53 +0800 | |
---|---|---|
committer | 2017-08-08 14:02:53 +0800 | |
commit | c0604184b2aa8cff924ca783ec6b36f1f5988775 (patch) | |
tree | 1c70ffe1ad90c915b3382a37eb2fa80901519c7b /wso2/dropwizard-ioc-container/src/test/java/org/openo | |
parent | 706fc9fed496972968fde136c3e4e10f9578a5b3 (diff) |
init code
Change-Id: Icd0948118397b256da70dfbcbbec5520dc5eafd4
Signed-off-by: Zhaoxing <meng.zhaoxing1@zte.com.cn>
Diffstat (limited to 'wso2/dropwizard-ioc-container/src/test/java/org/openo')
5 files changed, 184 insertions, 0 deletions
diff --git a/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/IOCBundleTest.java b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/IOCBundleTest.java new file mode 100644 index 0000000..b0cac65 --- /dev/null +++ b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/IOCBundleTest.java @@ -0,0 +1,49 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed 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.openo.dropwizard.ioc.test.service; + +import org.glassfish.hk2.api.ServiceLocator; +import org.junit.Before; +import org.junit.Test; +import org.openo.dropwizard.ioc.test.service.app.ExampleApp; +import org.openo.dropwizard.ioc.utils.ServiceLocatorHolder; + +import junit.framework.Assert; + +public class IOCBundleTest { + + + + @Before + public void setUp() throws Exception { + ExampleApp.main(null); + } + + @Test + public void test() { + + ServiceLocator locator = ServiceLocatorHolder.getLocator(); + + TestService testService = locator.getService(TestService.class); + + Assert.assertNotNull(testService); + + Assert.assertEquals(TestService.HELLO, testService.sayHello()); + + Assert.assertEquals(PreTestService.HELLO, testService.sayHelloToPreTestService()); + } + +} diff --git a/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/PreTestService.java b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/PreTestService.java new file mode 100644 index 0000000..51cc386 --- /dev/null +++ b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/PreTestService.java @@ -0,0 +1,33 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed 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.openo.dropwizard.ioc.test.service; + +import org.openo.dropwizard.ioc.annotation.PreServiceLoad; + +/** + * @author hu.rui + * + */ +@PreServiceLoad +public class PreTestService { + + public static final String HELLO = "hello Pre Service"; + + public String sayHello(){ + return HELLO; + } + +} diff --git a/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/TestService.java b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/TestService.java new file mode 100644 index 0000000..3d0f945 --- /dev/null +++ b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/TestService.java @@ -0,0 +1,41 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed 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.openo.dropwizard.ioc.test.service; + +import javax.inject.Inject; + +import org.jvnet.hk2.annotations.Service; + +/** + * @author hu.rui + * + */ +@Service +public class TestService { + + @Inject + private PreTestService preTestService; + + public static final String HELLO = "hello Service"; + + public String sayHello(){ + return HELLO; + } + + public String sayHelloToPreTestService(){ + return preTestService.sayHello(); + } +} diff --git a/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/app/ExampleApp.java b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/app/ExampleApp.java new file mode 100644 index 0000000..1e1f3ea --- /dev/null +++ b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/app/ExampleApp.java @@ -0,0 +1,35 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed 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.openo.dropwizard.ioc.test.service.app; + +import org.openo.dropwizard.ioc.bundle.IOCApplication; +import org.openo.dropwizard.ioc.test.service.conf.TestConfiguration; + +public class ExampleApp extends IOCApplication<TestConfiguration>{ + + private static final String CONFIGURATION_FILE = "example.yml"; + + public static void main(String[] args) throws Exception { + + String configFile = ExampleApp.class.getClassLoader().getResource(CONFIGURATION_FILE).getFile(); + + args = new String[]{"server",configFile}; + + new ExampleApp().run(args); + } + + +} diff --git a/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/conf/TestConfiguration.java b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/conf/TestConfiguration.java new file mode 100644 index 0000000..82c30cd --- /dev/null +++ b/wso2/dropwizard-ioc-container/src/test/java/org/openo/dropwizard/ioc/test/service/conf/TestConfiguration.java @@ -0,0 +1,26 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed 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.openo.dropwizard.ioc.test.service.conf; + +import io.dropwizard.Configuration; + +/** + * @author hu.rui + * + */ +public class TestConfiguration extends Configuration { + +} |