You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/22 04:17:49 UTC

[shardingsphere-elasticjob] branch master updated: Add test case for AopTargetUtils (#1226)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new fa5ea50  Add test case for AopTargetUtils (#1226)
fa5ea50 is described below

commit fa5ea5089a5f3fc012131d5f8a1086d9b4e43826
Author: 于玉桔 <zh...@apache.org>
AuthorDate: Wed Jul 22 12:17:41 2020 +0800

    Add test case for AopTargetUtils (#1226)
    
    * Add test case for AopTargetUtils
---
 .../namespace/job/util/AopTargetUtilsTest.java     | 58 ++++++++++++++++++++++
 .../lite/spring/namespace/job/util/TargetJob.java  | 33 ++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/AopTargetUtilsTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/AopTargetUtilsTest.java
new file mode 100644
index 0000000..7d77363
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/AopTargetUtilsTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.shardingsphere.elasticjob.lite.spring.namespace.job.util;
+
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.junit.Test;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.aop.support.AopUtils;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class AopTargetUtilsTest {
+    
+    @Test
+    public void assertJdkDynamicProxyForGetTarget() {
+        ElasticJob target = new TargetJob();
+        ProxyFactory pf = new ProxyFactory(target);
+        pf.addInterface(ElasticJob.class);
+        ElasticJob proxy = (ElasticJob) pf.getProxy();
+        assertTrue(AopUtils.isJdkDynamicProxy(proxy));
+        assertThat(AopTargetUtils.getTarget(proxy), is(target));
+    }
+    
+    @Test
+    public void assertCglibProxyForGetTarget() {
+        ElasticJob target = new TargetJob();
+        ProxyFactory pf = new ProxyFactory(target);
+        pf.setProxyTargetClass(true);
+        ElasticJob proxy = (ElasticJob) pf.getProxy();
+        assertTrue(AopUtils.isCglibProxy(proxy));
+        assertThat(AopTargetUtils.getTarget(proxy), is(target));
+    }
+    
+    @Test
+    public void assertNoneProxyForGetTarget() {
+        ElasticJob proxy = new TargetJob();
+        assertFalse(AopUtils.isAopProxy(proxy));
+        assertThat(AopTargetUtils.getTarget(proxy), is(proxy));
+    }
+}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/TargetJob.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/TargetJob.java
new file mode 100644
index 0000000..6b861b8
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/util/TargetJob.java
@@ -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.shardingsphere.elasticjob.lite.spring.namespace.job.util;
+
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+
+public class TargetJob implements ElasticJob {
+    
+    /**
+     * Mocker object for AopTargetUtilsTest.
+     *
+     * @param shardingContext shardingContext
+     */
+    public void execute(final ShardingContext shardingContext) {
+    
+    }
+}