aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/org/aspectj/systemtest/apt
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2019-01-30 16:55:38 -0800
committerAndy Clement <aclement@pivotal.io>2019-01-30 16:55:38 -0800
commit2b24e7377da7c849fe7f9f4fa06a701664f9d27d (patch)
tree64c36c8fcf29633af7a5e2f7405b94cbec629ca8 /tests/src/test/java/org/aspectj/systemtest/apt
parentd60de8d0b3e62eb36b612a824bb9345d865c0155 (diff)
downloadaspectj-2b24e7377da7c849fe7f9f4fa06a701664f9d27d.tar.gz
aspectj-2b24e7377da7c849fe7f9f4fa06a701664f9d27d.zip
mavenizing tests - wip
Diffstat (limited to 'tests/src/test/java/org/aspectj/systemtest/apt')
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/apt/AllTestsApt.java25
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/apt/AptTests.java65
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/apt/apt-spec.xml101
3 files changed, 191 insertions, 0 deletions
diff --git a/tests/src/test/java/org/aspectj/systemtest/apt/AllTestsApt.java b/tests/src/test/java/org/aspectj/systemtest/apt/AllTestsApt.java
new file mode 100644
index 000000000..fbba0be31
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/apt/AllTestsApt.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.apt;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTestsApt {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Annotation processing tests");
+ // $JUnit-BEGIN$
+ suite.addTest(AptTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/apt/AptTests.java b/tests/src/test/java/org/aspectj/systemtest/apt/AptTests.java
new file mode 100644
index 000000000..01ab16ca0
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/apt/AptTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2014,2018 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.apt;
+
+import java.io.File;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.util.LangUtil;
+
+import junit.framework.Test;
+
+/**
+ * Annotation processing tool tests.
+ *
+ * @author Sergey Stupin.
+ */
+public class AptTests extends XMLBasedAjcTestCase {
+
+ public void testAptWithSpecifiedProcessor() {
+ if (LangUtil.is19VMOrGreater()) {
+ return;
+ }
+ runTest("annotation processing with specified processor");
+ }
+
+ /**
+ * SPI - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
+ */
+ public void testAptUsingSPI() {
+ if (LangUtil.is19VMOrGreater()) {
+ return;
+ }
+ runTest("annotation processing in action using SPI");
+ }
+
+ public void testDisabledApt() {
+ if (LangUtil.is11VMOrGreater()) {
+ // javax.annotation.Generated not in Java11
+ return;
+ }
+ runTest("disabled annotation processing");
+ }
+
+ public void testAptWithJavaFilesAsAspects() {
+ runTest("annotation processing generating java files with aspects");
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(AptTests.class);
+ }
+
+ @Override
+ protected File getSpecFile() {
+ return getClassResource("apt-spec.xml");
+ }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/apt/apt-spec.xml b/tests/src/test/java/org/aspectj/systemtest/apt/apt-spec.xml
new file mode 100644
index 000000000..0ce327c49
--- /dev/null
+++ b/tests/src/test/java/org/aspectj/systemtest/apt/apt-spec.xml
@@ -0,0 +1,101 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+ <ajc-test dir="apt/test1" title="annotation processing with specified processor">
+ <compile options="-1.8" files="Event.java SimpleProcessor.java"
+ outjar="annotation_processor.jar"/>
+ <!--
+ SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
+ - {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emmiter);
+ }
+ }
+ -->
+ <!-- believe fails on JDK9 because of split packages and unable to find @Generated -->
+ <compile options="-1.8 -processor test.SimpleProcessor -s generated -showWeaveInfo" files="Some.java"
+ classpath="annotation_processor.jar" outjar="code.jar">
+ <message kind="weave"
+ text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/>
+ </compile>
+ <run class="test.Some">
+ <stdout>
+ <line text="callback registered from before aspect"/>
+ <line text="method1 is invoked"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="apt/test1" title="annotation processing in action using SPI">
+ <!--
+ what is SPI is described here - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
+ -->
+ <!--<compile options="-1.8" files="Event.java SimpleProcessor.java" outjar="annotation_processors_with_spi.jar"/>-->
+ <compile options="-1.8" files="Event.java SimpleProcessor.java" outjar="annotation_processor.jar"/>
+ <!--
+ SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
+ - {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emitter);
+ }
+ }
+ -->
+
+ <!--apt_service_description.jar contains only SPI description file - META-INF/services/javax.annotation.processing.Processor-->
+ <compile options="-1.8 -s generated -showWeaveInfo" files="Some.java"
+ classpath="annotation_processor.jar;apt_service_description.jar" outjar="code.jar">
+ <message kind="weave"
+ text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/>
+ </compile>
+
+ <run class="test.Some">
+ <stdout>
+ <line text="callback registered from before aspect"/>
+ <line text="method1 is invoked"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="apt/test1" title="disabled annotation processing">
+ <compile options="-1.8" files="Event.java SimpleProcessor.java"
+ outjar="annotation_processor.jar"/>
+ <!--
+ SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
+ - {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emmiter);
+ }
+ }
+ -->
+
+ <compile options="-1.8 -s generated -showWeaveInfo -proc:none" files="Some.java"
+ classpath="annotation_processor.jar" outjar="code.jar">
+ <!--field was not injected, so error should occur-->
+ <message kind="error" text="OnMethod1Event cannot be resolved or is not a field"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="apt/test2" title="annotation processing generating java files with aspects">
+ <compile options="-1.6" files="DemoProcessor.java Marker.java" />
+ <compile options="-1.6 -showWeaveInfo -processor DemoProcessor" files="Code.java">
+ <message kind="warning" text="Generated aspect to advise too"/>
+ <message kind="warning" text="Generated aspect to advise boo"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void Code.boo())' in Type 'Code' (Code.java:6) advised by before advice from 'Advise_boo' (Advise_boo.java:2)"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void Code.too())' in Type 'Code' (Code.java:9) advised by before advice from 'Advise_too' (Advise_too.java:2)"/>
+ </compile>
+ </ajc-test>
+
+</suite>