From d9d56ff2e134b40d6c07d30ce1fba3e9e8b9ec97 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 5 Feb 2016 12:42:46 +0800 Subject: [PATCH] refactor test case for spring namespace --- .../job/spring/util/AopTargetUtils.java | 8 ++-- .../ddframe/job/AllSpringJobTests.java | 6 +-- .../AbstractJobSpringIntegrateTest.java | 18 +++++--- .../ddframe/job/spring/WithNamespaceTest.java | 7 ++- .../job/spring/WithoutNamespaceTest.java | 7 ++- .../failure/ClassNotElasticJobTest.java | 43 ------------------- .../job/spring/failure/ClassNotFoundTest.java | 43 ------------------- .../META-INF/job/classNotElasticJob.xml | 15 ------- .../resources/META-INF/job/classNotFound.xml | 15 ------- .../resources/META-INF/job/withNamespace.xml | 4 +- .../META-INF/job/withoutNamespace.xml | 8 ++-- 11 files changed, 35 insertions(+), 139 deletions(-) delete mode 100644 elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotElasticJobTest.java delete mode 100644 elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotFoundTest.java delete mode 100644 elastic-job-spring/src/test/resources/META-INF/job/classNotElasticJob.xml delete mode 100644 elastic-job-spring/src/test/resources/META-INF/job/classNotFound.xml diff --git a/elastic-job-spring/src/main/java/com/dangdang/ddframe/job/spring/util/AopTargetUtils.java b/elastic-job-spring/src/main/java/com/dangdang/ddframe/job/spring/util/AopTargetUtils.java index 33a2b785f6..9c5b9b8f0c 100644 --- a/elastic-job-spring/src/main/java/com/dangdang/ddframe/job/spring/util/AopTargetUtils.java +++ b/elastic-job-spring/src/main/java/com/dangdang/ddframe/job/spring/util/AopTargetUtils.java @@ -24,16 +24,17 @@ import com.dangdang.ddframe.job.exception.JobException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * 基于Spring AOP获取目标对象. * * @author caohao */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AopTargetUtils { - private AopTargetUtils() { - } - /** * 获取目标对象. * @@ -64,7 +65,6 @@ private static Object getProxyTargetObject(final Object proxy, final String prox } catch (final IllegalAccessException ex) { throw new JobException(ex); } - } private static Object getProxyTargetObjectForCglibAndSpring4(final Object proxy) { diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/AllSpringJobTests.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/AllSpringJobTests.java index 6f4d3a90d4..1edb706aa3 100644 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/AllSpringJobTests.java +++ b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/AllSpringJobTests.java @@ -23,15 +23,11 @@ import com.dangdang.ddframe.job.spring.WithNamespaceTest; import com.dangdang.ddframe.job.spring.WithoutNamespaceTest; -import com.dangdang.ddframe.job.spring.failure.ClassNotElasticJobTest; -import com.dangdang.ddframe.job.spring.failure.ClassNotFoundTest; @RunWith(Suite.class) @SuiteClasses({ WithNamespaceTest.class, - WithoutNamespaceTest.class, - ClassNotFoundTest.class, - ClassNotElasticJobTest.class + WithoutNamespaceTest.class }) public class AllSpringJobTests { } diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/AbstractJobSpringIntegrateTest.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/AbstractJobSpringIntegrateTest.java index 0a3035832d..1b32d0b7d4 100644 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/AbstractJobSpringIntegrateTest.java +++ b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/AbstractJobSpringIntegrateTest.java @@ -35,8 +35,15 @@ import com.dangdang.ddframe.test.AbstractZookeeperJUnit4SpringContextTests; import com.dangdang.ddframe.test.WaitingUtils; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor public abstract class AbstractJobSpringIntegrateTest extends AbstractZookeeperJUnit4SpringContextTests { + private final String simpleJobName; + + private final String throughputDataFlowJobName; + @Resource private CoordinatorRegistryCenter regCenter; @@ -45,14 +52,13 @@ public abstract class AbstractJobSpringIntegrateTest extends AbstractZookeeperJU public void reset() { SimpleElasticJob.reset(); ThroughputDataFlowElasticJob.reset(); - ProcessCountStatistics.reset("testJob"); + ProcessCountStatistics.reset(throughputDataFlowJobName); } @After public void tearDown() { - JobRegistry.getInstance().getJobScheduler("simpleElasticJob").shutdown(); - JobRegistry.getInstance().getJobScheduler("throughputDataFlowElasticJob").shutdown(); - WaitingUtils.waitingLongTime(); + JobRegistry.getInstance().getJobScheduler(simpleJobName).shutdown(); + JobRegistry.getInstance().getJobScheduler(throughputDataFlowJobName).shutdown(); } @Test @@ -67,7 +73,7 @@ private void assertSimpleElasticJobBean() { } assertTrue(SimpleElasticJob.isCompleted()); assertThat(SimpleElasticJob.getJobValue(), is("simple")); - assertTrue(regCenter.isExisted("/simpleElasticJob/execution")); + assertTrue(regCenter.isExisted("/" + simpleJobName + "/execution")); } private void assertThroughputDataFlowElasticJobBean() { @@ -75,6 +81,6 @@ private void assertThroughputDataFlowElasticJobBean() { WaitingUtils.waitingShortTime(); } assertTrue(ThroughputDataFlowElasticJob.isCompleted()); - assertTrue(regCenter.isExisted("/throughputDataFlowElasticJob/execution")); + assertTrue(regCenter.isExisted("/" + throughputDataFlowJobName + "/execution")); } } diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithNamespaceTest.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithNamespaceTest.java index 3ebe5c42f2..aed586023f 100644 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithNamespaceTest.java +++ b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithNamespaceTest.java @@ -20,4 +20,9 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations = "classpath:META-INF/job/withNamespace.xml") -public final class WithNamespaceTest extends AbstractJobSpringIntegrateTest { } +public final class WithNamespaceTest extends AbstractJobSpringIntegrateTest { + + public WithNamespaceTest() { + super("simpleElasticJob_namespace", "throughputDataFlowElasticJob_namespace"); + } +} diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithoutNamespaceTest.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithoutNamespaceTest.java index 5b1632f044..21c343a139 100644 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithoutNamespaceTest.java +++ b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/WithoutNamespaceTest.java @@ -20,4 +20,9 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations = "classpath:META-INF/job/withoutNamespace.xml") -public final class WithoutNamespaceTest extends AbstractJobSpringIntegrateTest { } +public final class WithoutNamespaceTest extends AbstractJobSpringIntegrateTest { + + public WithoutNamespaceTest() { + super("simpleElasticJob_no_namespace", "throughputDataFlowElasticJob_no_namespace"); + } +} diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotElasticJobTest.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotElasticJobTest.java deleted file mode 100644 index 7f84991c17..0000000000 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotElasticJobTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 1999-2015 dangdang.com. - *

- * 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 com.dangdang.ddframe.job.spring.failure; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.dangdang.ddframe.test.NestedZookeeperServers; - -public final class ClassNotElasticJobTest { - - @Before - public void setUp() { - NestedZookeeperServers.getInstance().startServerIfNotStarted(); - } - - @SuppressWarnings("resource") - @Test(expected = BeanCreationException.class) - public void assertNotElasticJob() { - try { - new ClassPathXmlApplicationContext("classpath:META-INF/job/classNotElasticJob.xml"); - } catch (final BeanCreationException ex) { - throw ex; - } - } -} diff --git a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotFoundTest.java b/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotFoundTest.java deleted file mode 100644 index bcb989869b..0000000000 --- a/elastic-job-spring/src/test/java/com/dangdang/ddframe/job/spring/failure/ClassNotFoundTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 1999-2015 dangdang.com. - *

- * 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 com.dangdang.ddframe.job.spring.failure; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.dangdang.ddframe.test.NestedZookeeperServers; - -public final class ClassNotFoundTest { - - @Before - public void setUp() { - NestedZookeeperServers.getInstance().startServerIfNotStarted(); - } - - @SuppressWarnings("resource") - @Test(expected = BeanCreationException.class) - public void assertJobClassNotFound() { - try { - new ClassPathXmlApplicationContext("classpath:META-INF/job/classNotFound.xml"); - } catch (final BeanCreationException ex) { - throw ex; - } - } -} diff --git a/elastic-job-spring/src/test/resources/META-INF/job/classNotElasticJob.xml b/elastic-job-spring/src/test/resources/META-INF/job/classNotElasticJob.xml deleted file mode 100644 index a011e06aca..0000000000 --- a/elastic-job-spring/src/test/resources/META-INF/job/classNotElasticJob.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/elastic-job-spring/src/test/resources/META-INF/job/classNotFound.xml b/elastic-job-spring/src/test/resources/META-INF/job/classNotFound.xml deleted file mode 100644 index 06cc00d030..0000000000 --- a/elastic-job-spring/src/test/resources/META-INF/job/classNotFound.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/elastic-job-spring/src/test/resources/META-INF/job/withNamespace.xml b/elastic-job-spring/src/test/resources/META-INF/job/withNamespace.xml index c2ea29a1b8..b1bf51e4fc 100644 --- a/elastic-job-spring/src/test/resources/META-INF/job/withNamespace.xml +++ b/elastic-job-spring/src/test/resources/META-INF/job/withNamespace.xml @@ -16,8 +16,8 @@ - - + + diff --git a/elastic-job-spring/src/test/resources/META-INF/job/withoutNamespace.xml b/elastic-job-spring/src/test/resources/META-INF/job/withoutNamespace.xml index 046fc16b41..9e79207ab3 100644 --- a/elastic-job-spring/src/test/resources/META-INF/job/withoutNamespace.xml +++ b/elastic-job-spring/src/test/resources/META-INF/job/withoutNamespace.xml @@ -21,11 +21,11 @@ - + - + @@ -36,11 +36,11 @@ - + - +