Several changes in the junit4osgi subproject (copy preparation)
Add LICENCE and NOTICE files
Add licence header
Format the code
The groupId is now org.apache.felix
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@722135 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/examples/junit4osgi/felix-command/LICENSE b/ipojo/examples/junit4osgi/felix-command/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/examples/junit4osgi/felix-command/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/ipojo/examples/junit4osgi/felix-command/NOTICE b/ipojo/examples/junit4osgi/felix-command/NOTICE
new file mode 100644
index 0000000..c0a0c56
--- /dev/null
+++ b/ipojo/examples/junit4osgi/felix-command/NOTICE
@@ -0,0 +1,17 @@
+Apache Felix iPOJO junit4osgi Felix Command
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
diff --git a/ipojo/examples/junit4osgi/felix-command/metadata.xml b/ipojo/examples/junit4osgi/felix-command/metadata.xml
index 87f7db1..4021649 100644
--- a/ipojo/examples/junit4osgi/felix-command/metadata.xml
+++ b/ipojo/examples/junit4osgi/felix-command/metadata.xml
@@ -1,9 +1,27 @@
+<!--
+ 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.
+-->
<?xml version="1.0" encoding="UTF-8"?>
<iPOJO>
<component
className="org.apache.felix.ipojo.junit4osgi.command.JunitCommand"
factory="false">
- <requires field="runner" />
+ <requires field="m_runner" />
<provides />
</component>
<instance
diff --git a/ipojo/examples/junit4osgi/felix-command/pom.xml b/ipojo/examples/junit4osgi/felix-command/pom.xml
index 6f6749c..6b912ad 100644
--- a/ipojo/examples/junit4osgi/felix-command/pom.xml
+++ b/ipojo/examples/junit4osgi/felix-command/pom.xml
@@ -23,7 +23,7 @@
<artifactId>
org.apache.felix.ipojo.junit4osgi.felix-command
</artifactId>
- <groupId>ipojo.examples</groupId>
+ <groupId>org.apache.felix</groupId>
<version>1.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
@@ -59,15 +59,13 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Name>
- iPOJO OSGi Junit Runner - Felix Command
+ <Bundle-Name> iPOJO OSGi Junit Runner - Felix Command
</Bundle-Name>
- <Bundle-SymbolicName>
- ${pom.artifactId}
- </Bundle-SymbolicName>
- <Private-Package>
- org.apache.felix.ipojo.junit4osgi.command
+ <Bundle-SymbolicName> ${pom.artifactId}</Bundle-SymbolicName>
+ <Private-Package> org.apache.felix.ipojo.junit4osgi.command
</Private-Package>
+ <Include-Resource> META-INF/LICENCE=LICENSE,
+ META-INF/NOTICE=NOTICE </Include-Resource>
</instructions>
</configuration>
</plugin>
@@ -86,6 +84,31 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin
+ </artifactId>
+ <configuration>
+ <configLocation>
+ http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml
+ </configLocation>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/ipojo/examples/junit4osgi/felix-command/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java b/ipojo/examples/junit4osgi/felix-command/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java
index 1a16e44..74ffac2 100644
--- a/ipojo/examples/junit4osgi/felix-command/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java
+++ b/ipojo/examples/junit4osgi/felix-command/src/main/java/org/apache/felix/ipojo/junit4osgi/command/JunitCommand.java
@@ -38,8 +38,16 @@
*/
public class JunitCommand implements Command {
- private OSGiJunitRunner runner;
+ /**
+ * OSGi Junit Runner service.
+ */
+ private OSGiJunitRunner m_runner;
+ /**
+ * Gets the Test names.
+ * @param list the list of test
+ * @return the list of test names.
+ */
private List getNamesFromTests(List list) {
List names = new ArrayList(list.size());
for (int i = 0; i < list.size(); i++) {
@@ -57,26 +65,33 @@
return names;
}
+ /**
+ * Executes the command.
+ * @param line the command line
+ * @param out the output stream
+ * @param err the error stream
+ * @see org.apache.felix.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
+ */
public void execute(String line, PrintStream out, PrintStream err) {
line = line.substring(getName().length()).trim();
List tr = null;
if (line.equals("all")) {
- if (runner.getTests() == null) {
+ if (m_runner.getTests() == null) {
err.println("No tests to execute");
return;
} else {
- out.println("Executing " + getNamesFromTests(runner.getTests()));
- tr = runner.run();
+ out.println("Executing " + getNamesFromTests(m_runner.getTests()));
+ tr = m_runner.run();
}
} else {
try {
Long bundleId = new Long(line);
- if (runner.getTests(bundleId.longValue()) == null) {
+ if (m_runner.getTests(bundleId.longValue()) == null) {
err.println("No tests to execute");
return;
} else {
- out.println("Executing " + getNamesFromTests(runner.getTests(bundleId.longValue())));
- tr = runner.run(bundleId.longValue());
+ out.println("Executing " + getNamesFromTests(m_runner.getTests(bundleId.longValue())));
+ tr = m_runner.run(bundleId.longValue());
}
} catch (NumberFormatException e) {
err.println("Unable to parse id " + line);
@@ -96,16 +111,31 @@
}
+ /**
+ * Gets the command name.
+ * @return "junit"
+ * @see org.apache.felix.shell.Command#getName()
+ */
public String getName() {
return "junit";
}
+ /**
+ * Gets a small description of the command.
+ * @return "launch junit tests"
+ * @see org.apache.felix.shell.Command#getShortDescription()
+ */
public String getShortDescription() {
return "launch junit tests";
}
+ /**
+ * Gets command usage.
+ * @return the command usage.
+ * @see org.apache.felix.shell.Command#getUsage()
+ */
public String getUsage() {
- return "junit";
+ return "junit <bundleid> | junit all";
}
}
diff --git a/ipojo/examples/junit4osgi/immediate-launcher/LICENSE b/ipojo/examples/junit4osgi/immediate-launcher/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/examples/junit4osgi/immediate-launcher/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/ipojo/examples/junit4osgi/immediate-launcher/NOTICE b/ipojo/examples/junit4osgi/immediate-launcher/NOTICE
new file mode 100644
index 0000000..7324e07
--- /dev/null
+++ b/ipojo/examples/junit4osgi/immediate-launcher/NOTICE
@@ -0,0 +1,17 @@
+Apache Felix iPOJO junit4osgi Immediate Runner
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
diff --git a/ipojo/examples/junit4osgi/immediate-launcher/metadata.xml b/ipojo/examples/junit4osgi/immediate-launcher/metadata.xml
index 648ab67..4d7392a 100644
--- a/ipojo/examples/junit4osgi/immediate-launcher/metadata.xml
+++ b/ipojo/examples/junit4osgi/immediate-launcher/metadata.xml
@@ -1,9 +1,27 @@
+<!--
+ 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.
+-->
<?xml version="1.0" encoding="UTF-8"?>
<iPOJO>
<component
className="org.apache.felix.ipojo.junit4osgi.command.ImmediateRunner"
factory="false">
- <requires field="runner" />
+ <requires field="m_runner" />
<callback method="start" transition="validate" />
</component>
<instance
diff --git a/ipojo/examples/junit4osgi/immediate-launcher/pom.xml b/ipojo/examples/junit4osgi/immediate-launcher/pom.xml
index 8a9f41d..0328d91 100644
--- a/ipojo/examples/junit4osgi/immediate-launcher/pom.xml
+++ b/ipojo/examples/junit4osgi/immediate-launcher/pom.xml
@@ -23,7 +23,7 @@
<artifactId>
org.apache.felix.ipojo.junit4osgi.immediate-runner
</artifactId>
- <groupId>ipojo.examples</groupId>
+ <groupId>org.apache.felix</groupId>
<version>1.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
@@ -59,15 +59,13 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Name>
- iPOJO OSGi Junit Runner - Immediate Runner
+ <Bundle-Name> iPOJO OSGi Junit Runner - Immediate Runner
</Bundle-Name>
- <Bundle-SymbolicName>
- ${pom.artifactId}
- </Bundle-SymbolicName>
- <Private-Package>
- org.apache.felix.ipojo.junit4osgi.command
+ <Bundle-SymbolicName> ${pom.artifactId}</Bundle-SymbolicName>
+ <Private-Package> org.apache.felix.ipojo.junit4osgi.command
</Private-Package>
+ <Include-Resource> META-INF/LICENCE=LICENSE,
+ META-INF/NOTICE=NOTICE </Include-Resource>
</instructions>
</configuration>
</plugin>
@@ -86,6 +84,31 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin
+ </artifactId>
+ <configuration>
+ <configLocation>
+ http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml
+ </configLocation>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/ipojo/examples/junit4osgi/immediate-launcher/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ImmediateRunner.java b/ipojo/examples/junit4osgi/immediate-launcher/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ImmediateRunner.java
index 199cdf6..1cc0a59 100644
--- a/ipojo/examples/junit4osgi/immediate-launcher/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ImmediateRunner.java
+++ b/ipojo/examples/junit4osgi/immediate-launcher/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ImmediateRunner.java
@@ -21,15 +21,22 @@
import org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner;
/**
- * Felix shell command. Allow to run tests.
+ * Junit Immediate runner.
+ * Executes test when starts.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class ImmediateRunner {
- private OSGiJunitRunner runner;
+ /**
+ * OSGi Junit Runner service.
+ */
+ private OSGiJunitRunner m_runner;
+ /**
+ * Start method.
+ */
public void start() {
- runner.run();
+ m_runner.run();
}
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/LICENSE b/ipojo/examples/junit4osgi/junit4osgi/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/examples/junit4osgi/junit4osgi/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/ipojo/examples/junit4osgi/junit4osgi/NOTICE b/ipojo/examples/junit4osgi/junit4osgi/NOTICE
new file mode 100644
index 0000000..9c51625
--- /dev/null
+++ b/ipojo/examples/junit4osgi/junit4osgi/NOTICE
@@ -0,0 +1,22 @@
+Apache Felix iPOJO junit4osgi Framework
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed by
+Junit project (http://junit.org)
+Licensed under Common Public License 1.0.
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
+- Common Public License 1.0
diff --git a/ipojo/examples/junit4osgi/junit4osgi/metadata.xml b/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
index 9fd4d99..db0dc94 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
+++ b/ipojo/examples/junit4osgi/junit4osgi/metadata.xml
@@ -1,3 +1,21 @@
+<!--
+ 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.
+-->
<?xml version="1.0" encoding="UTF-8"?>
<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd
diff --git a/ipojo/examples/junit4osgi/junit4osgi/pom.xml b/ipojo/examples/junit4osgi/junit4osgi/pom.xml
index 2737035..26db137 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/pom.xml
+++ b/ipojo/examples/junit4osgi/junit4osgi/pom.xml
@@ -21,7 +21,7 @@
<packaging>bundle</packaging>
<name>Junit4Osgi</name>
<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
- <groupId>ipojo.examples</groupId>
+ <groupId>org.apache.felix</groupId>
<version>1.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
@@ -79,6 +79,8 @@
org.apache.felix.ipojo.junit4osgi.test.TestTestSuite,
org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestSuite,
</Test-Suite> -->
+ <Include-Resource> META-INF/LICENCE=LICENSE,
+ META-INF/NOTICE=NOTICE </Include-Resource>
</instructions>
</configuration>
</plugin>
@@ -97,6 +99,29 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <configLocation>http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml</configLocation>
+ <violationSeverity>error</violationSeverity>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/Helper.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/Helper.java
new file mode 100644
index 0000000..9909b68
--- /dev/null
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/Helper.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.felix.ipojo.junit4osgi;
+
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * Helper abstract class.
+ * Helper objects aim to facilitate Test writing.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public abstract class Helper {
+
+ /**
+ * The bundle context.
+ */
+ protected BundleContext m_context;
+
+ /**
+ * The OSGi Test case.
+ */
+ protected OSGiTestCase m_testcase;
+
+ /**
+ * Creates a Helper.
+ * Registers the helper.
+ * Sub-classes must initialize the session.
+ * @param tc the OSGi Test Case
+ */
+ public Helper(OSGiTestCase tc) {
+ m_testcase = tc;
+ m_context = m_testcase.getBundleContext();
+ tc.addHelper(this);
+ }
+
+ /**
+ * Rolls back the session.
+ */
+ public abstract void dispose();
+
+}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java
index 7998a55..334e311 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiJunitRunner.java
@@ -32,7 +32,7 @@
/**
* Set the output stream of the runner.
- * @param ps : print stream.
+ * @param ps the print stream.
*/
void setResultPrinter(PrintStream ps);
@@ -44,7 +44,7 @@
/**
* Run the tests from the given bundle.
- * @param bundleId : bundle containing the tests.
+ * @param bundleId the bundle id containing the tests.
* @return the list of the test results.
*/
List/*<TestResult>*/ run(long bundleId);
@@ -57,16 +57,16 @@
/**
* Get the tests from the given bundle.
- * @param bundleId : bundle id.
+ * @param bundleId the bundle id.
* @return the list of Test contained in the given bundle.
*/
List/*<Test>*/ getTests(long bundleId);
/**
* Run the given test.
- * @param test : test to execute.
+ * @param test the test to execute.
* @return the result.
*/
- public TestResult run(Test test);
+ TestResult run(Test test);
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
index 6a860ad..952f823 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestCase.java
@@ -29,441 +29,538 @@
import org.osgi.framework.ServiceReference;
/**
- * OSGi Test Case. Allow the injection of the bundle context.
+ * OSGi Test Case.
+ * Allows the injection of the bundle context.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class OSGiTestCase extends TestCase {
- protected BundleContext context;
-
-
- private List references = new ArrayList();
-
+ /**
+ * The bundle context.
+ */
+ protected BundleContext context;
+
+ /**
+ * List of get references.
+ */
+ private List m_references = new ArrayList();
+
+ /**
+ * List of helpers.
+ */
+ private List m_helpers = new ArrayList();
+
+ /**
+ * Gets the Bundle Context.
+ * @return the bundle context.
+ */
+ public BundleContext getContext() {
+ return context;
+ }
+
+ /**
+ * Add an helper.
+ * This method is called by the {@link Helper#Helper(OSGiTestCase)}
+ * method.
+ * @param helper the helper object.
+ */
+ public void addHelper(Helper helper) {
+ m_helpers.add(helper);
+ }
+
/**
* Extends runBare to release (unget) services after the teardown.
* @throws Throwable when an error occurs.
* @see junit.framework.TestCase#runBare()
*/
public void runBare() throws Throwable {
- super.runBare();
- // Unget services
- for (int i = 0; i < references.size(); i++) {
- context.ungetService((ServiceReference) references.get(i));
- }
- references.clear();
- }
+ setUp();
+ try {
+ runTest();
+ } finally {
+ tearDown();
+ // Stop Helpers
+ for (int i = 0; i < m_helpers.size(); i++) {
+ ((Helper) m_helpers.get(i)).dispose();
+ }
+ // Unget services
+ for (int i = 0; i < m_references.size(); i++) {
+ context.ungetService((ServiceReference) m_references.get(i));
+ }
+ m_references.clear();
+ }
+
+ }
- public void setBundleContext(BundleContext bc) {
- context = bc;
- }
-
- public BundleContext getBundleContext() {
- return context;
- }
+ public void setBundleContext(BundleContext bc) {
+ context = bc;
+ }
- public static void assertContains(String message, String[] array, String txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i].equals(txt)) {
- return;
- }
- }
- fail(formatContainsMessage(message, array, txt));
- }
+ public BundleContext getBundleContext() {
+ return context;
+ }
- public static void assertContains(String message, byte[] array, int txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Byte[] bytes = new Byte[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Byte(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Integer(txt)));
- }
+ /**
+ * Checks that the given string is contained in the given array.
+ * @param message the assert point message
+ * @param array the String array
+ * @param txt the String to search
+ */
+ public static void assertContains(String message, String[] array, String txt) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i].equals(txt)) {
+ return;
+ }
+ }
+ fail(formatContainsMessage(message, array, txt));
+ }
- public static void assertContains(String message, short[] array, int txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Short[] bytes = new Short[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Short(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Integer(txt)));
- }
+ /**
+ * Checks that the given integer is contained in the given array.
+ * @param message the assert point message
+ * @param array the byte array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, byte[] array, int num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Byte[] bytes = new Byte[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Byte(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Integer(num)));
+ }
- public static void assertContains(String message, int[] array, int txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Integer[] bytes = new Integer[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Integer(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Integer(txt)));
- }
+ /**
+ * Checks that the given integer is contained in the given array.
+ * @param message the assert point message
+ * @param array the short array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, short[] array, int num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Short[] bytes = new Short[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Short(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Integer(num)));
+ }
- public static void assertContains(String message, long[] array, long txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Long[] bytes = new Long[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Long(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Long(txt)));
- }
+ /**
+ * Checks that the given integer is contained in the given array.
+ * @param message the assert point message
+ * @param array the integer array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, int[] array, int num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Integer[] bytes = new Integer[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Integer(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Integer(num)));
+ }
- public static void assertContains(String message, float[] array, float txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Float[] bytes = new Float[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Float(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Float(txt)));
- }
+ /**
+ * Checks that the given long is contained in the given array.
+ * @param message the assert point message
+ * @param array the long array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, long[] array, long num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Long[] bytes = new Long[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Long(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Long(num)));
+ }
- public static void assertContains(String message, double[] array, double txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Double[] bytes = new Double[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Double(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Double(txt)));
- }
+ /**
+ * Checks that the given float is contained in the given array.
+ * @param message the assert point message
+ * @param array the float array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, float[] array, float num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Float[] bytes = new Float[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Float(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Float(num)));
+ }
- public static void assertContains(String message, char[] array, char txt) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == txt) {
- return;
- }
- }
- Character[] bytes = new Character[array.length];
- for (int i = 0; i < array.length; i++) {
- bytes[i] = new Character(array[i]);
- }
- fail(formatContainsMessage(message, bytes, new Character(txt)));
- }
+ /**
+ * Checks that the given double is contained in the given array.
+ * @param message the assert point message
+ * @param array the double array
+ * @param num the number to search
+ */
+ public static void assertContains(String message, double[] array, double num) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == num) {
+ return;
+ }
+ }
+ Double[] bytes = new Double[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Double(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Double(num)));
+ }
- /**
- * Asserts that two doubles are equal. If they are not an
- * AssertionFailedError is thrown with the given message.
- */
- public static void assertEquals(String message, double expected,
- double actual) {
- if (expected != actual) {
- fail(formatEqualsMessage(message, new Double(expected), new Double(
- actual)));
- }
- }
+ /**
+ * Checks that the given character is contained in the given array.
+ * @param message the assert point message
+ * @param array the character array
+ * @param character the character to search
+ */
+ public static void assertContains(String message, char[] array, char character) {
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == character) {
+ return;
+ }
+ }
+ Character[] bytes = new Character[array.length];
+ for (int i = 0; i < array.length; i++) {
+ bytes[i] = new Character(array[i]);
+ }
+ fail(formatContainsMessage(message, bytes, new Character(character)));
+ }
- public static void assertNotEquals(String message, Object o1, Object o2) {
- if (o1.equals(o2)) {
- fail(formatNotEqualsMessage(message, o1, o2));
- }
- }
+ /**
+ * Asserts that two doubles are equal. If they are not an
+ * AssertionFailedError is thrown with the given message.
+ * @param message the assert point message
+ * @param expected the expected double
+ * @param actual the received double
+ */
+ public static void assertEquals(String message, double expected,
+ double actual) {
+ if (expected != actual) {
+ fail(formatEqualsMessage(message, new Double(expected), new Double(
+ actual)));
+ }
+ }
- public static boolean contains(String string, String[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] != null && array[i].equals(string)) {
- return true;
- }
- }
- return false;
- }
+ /**
+ * Asserts that two objects are not equal. If they are an
+ * AssertionFailedError is thrown with the given message.
+ * @param message the assert point message
+ * @param o1 the unexpected object
+ * @param o2 the received object
+ */
+ public static void assertNotEquals(String message, Object o1, Object o2) {
+ if (o1.equals(o2)) {
+ fail(formatNotEqualsMessage(message, o1, o2));
+ }
+ }
- public static boolean contains(int value, int[] array) {
- for (int i = 0; array != null && i < array.length; i++) {
- if (array[i] == value) {
- return true;
- }
- }
- return false;
- }
+ /**
+ * Checks that the given string is contained in the given array.
+ * @param string the String to search
+ * @param array the String array
+ * @return <code>true</code> if the array contains the string
+ */
+ public static boolean contains(String string, String[] array) {
+ for (int i = 0; array != null && i < array.length; i++) {
+ if (array[i] != null && array[i].equals(string)) {
+ return true;
+ }
+ }
+ return false;
+ }
- private static String formatEqualsMessage(String message, Object expected,
- Object actual) {
- String formatted = "";
- if (message != null) {
- formatted = message + " ";
- }
- return formatted + "expected:<" + expected + "> but was:<" + actual
- + ">";
- }
+ /**
+ * Checks that the given integer is contained in the given array.
+ * @param value the number to search
+ * @param array the integer array
+ * @return <code>true</code> if the array contains the value
+ */
+ public static boolean contains(int value, int[] array) {
+ for (int i = 0; array != null && i < array.length; i++) {
+ if (array[i] == value) {
+ return true;
+ }
+ }
+ return false;
+ }
- private static String formatNotEqualsMessage(String message, Object o1,
- Object o2) {
- String formatted = "";
- if (message != null) {
- formatted = message + " ";
- }
- return formatted + "o1:<" + o1 + "> is equals to o2:<" + o2 + ">";
- }
+ /**
+ * Formats a failure message for 'equality' tests.
+ * @param message the assertion point message
+ * @param expected the expected value
+ * @param actual the received value
+ * @return the computed message
+ */
+ private static String formatEqualsMessage(String message, Object expected,
+ Object actual) {
+ String formatted = "";
+ if (message != null) {
+ formatted = message + " ";
+ }
+ return formatted + "expected:<" + expected + "> but was:<" + actual
+ + ">";
+ }
- private static String formatContainsMessage(String message, Object[] array,
- Object txt) {
- String formatted = "";
- if (message != null) {
- formatted = message + " ";
- }
+ /**
+ * Formats a failure message for 'un-equality' tests.
+ * @param message the assertion point message
+ * @param o1 the unexpected value
+ * @param o2 the received value
+ * @return the computed message
+ */
+ private static String formatNotEqualsMessage(String message, Object o1,
+ Object o2) {
+ String formatted = "";
+ if (message != null) {
+ formatted = message + " ";
+ }
+ return formatted + "o1:<" + o1 + "> is equals to o2:<" + o2 + ">";
+ }
- String arr = null;
- for (int i = 0; i < array.length; i++) {
- if (arr == null) {
- arr = "[" + array[i];
- } else {
- arr += "," + array[i];
- }
- }
- arr += "]";
+ /**
+ * Formats a failure message for 'contains' tests.
+ * @param message the assertion point message
+ * @param array the array
+ * @param txt the looked value
+ * @return the computed message
+ */
+ private static String formatContainsMessage(String message, Object[] array,
+ Object txt) {
+ String formatted = "";
+ if (message != null) {
+ formatted = message + " ";
+ }
- return formatted + "array:" + arr + " does not contains:<" + txt + ">";
- }
+ String arr = null;
+ for (int i = 0; i < array.length; i++) {
+ if (arr == null) {
+ arr = "[" + array[i];
+ } else {
+ arr += "," + array[i];
+ }
+ }
+ arr += "]";
-
+ return formatted + "array:" + arr + " does not contains:<" + txt + ">";
+ }
- /**
- * Returns the service object of a service provided by the specified bundle,
- * offering the specified interface and matching the given filter.
- *
- * @param bundle
- * the bundle in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return the service object provided by the specified bundle, offering the
- * specified interface and matching the given filter.
- */
- public static Object getServiceObject(Bundle bundle, String itf,
- String filter) {
- ServiceReference ref = getServiceReference(bundle, itf, filter);
- if (ref != null) {
- return bundle.getBundleContext().getService(ref);
- } else {
- return null;
- }
- }
+ /**
+ * Returns the service object of a service provided by the specified bundle,
+ * offering the specified interface and matching the given filter.
+ *
+ * @param bundle the bundle from which the service is searched.
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
+ * @return the service object provided by the specified bundle, offering the
+ * specified interface and matching the given filter.
+ */
+ public static Object getServiceObject(Bundle bundle, String itf,
+ String filter) {
+ ServiceReference ref = getServiceReference(bundle, itf, filter);
+ if (ref != null) {
+ return bundle.getBundleContext().getService(ref);
+ } else {
+ return null;
+ }
+ }
+ /**
+ * Returns the service objects of the services provided by the specified
+ * bundle, offering the specified interface and matching the given filter.
+ *
+ * @param bundle the bundle from which services are searched.
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
+ * @return the service objects provided by the specified bundle, offering
+ * the specified interface and matching the given filter.
+ */
+ public static Object[] getServiceObjects(Bundle bundle, String itf,
+ String filter) {
+ ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
+ if (refs != null) {
+ Object[] list = new Object[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ list[i] = bundle.getBundleContext().getService(refs[i]);
+ }
+ return list;
+ } else {
+ return new Object[0];
+ }
+ }
- /**
- * Returns the service objects of the services provided by the specified
- * bundle, offering the specified interface and matching the given filter.
- *
- * @param bundle
- * the bundle in which services are searched.
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return the service objects provided by the specified bundle, offering
- * the specified interface and matching the given filter.
- */
- public static Object[] getServiceObjects(Bundle bundle, String itf,
- String filter) {
- ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
- if (refs != null) {
- Object[] list = new Object[refs.length];
- for (int i = 0; i < refs.length; i++) {
- list[i] = bundle.getBundleContext().getService(refs[i]);
- }
- return list;
- } else {
- return new Object[0];
- }
- }
+ /**
+ * Returns the service reference of a service provided by the specified
+ * bundle, offering the specified interface and matching the given filter.
+ *
+ * @param bundle the bundle from which the service is searched.
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
+ * @return a service reference provided by the specified bundle, offering
+ * the specified interface and matching the given filter. If no
+ * service is found, {@code null} is returned.
+ */
+ public static ServiceReference getServiceReference(Bundle bundle,
+ String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
+ if (refs.length != 0) {
+ return refs[0];
+ } else {
+ // No service found
+ return null;
+ }
+ }
-
-
- /**
- * Returns the service reference of a service provided by the specified
- * bundle, offering the specified interface and matching the given filter.
- *
- * @param bundle
- * the bundle in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return a service reference provided by the specified bundle, offering
- * the specified interface and matching the given filter. If no
- * service is found, {@code null} is returned.
- */
- public static ServiceReference getServiceReference(Bundle bundle,
- String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
- if (refs.length != 0) {
- return refs[0];
- } else {
- // No service found
- return null;
- }
- }
-
- /**
- * Checks if the service is available.
- * @param itf the service interface
- * @return <code>true</code> if the service is available,
- * <code>false</code> otherwise.
- */
- public boolean isServiceAvailable(String itf) {
+ /**
+ * Checks if the service is available.
+ * @param itf the service interface
+ * @return <code>true</code> if the service is available, <code>false</code>
+ * otherwise.
+ */
+ public boolean isServiceAvailable(String itf) {
ServiceReference ref = getServiceReference(itf, null);
return ref != null;
}
-
+
/**
* Checks if the service is available.
* @param itf the service interface
* @param pid the service pid
- * @return <code>true</code> if the service is available,
- * <code>false</code> otherwise.
+ * @return <code>true</code> if the service is available, <code>false</code>
+ * otherwise.
*/
public boolean isServiceAvailableByPID(String itf, String pid) {
ServiceReference ref = getServiceReferenceByPID(itf, pid);
return ref != null;
}
-
-
- /**
- * Returns the service reference of the service provided by the specified
- * bundle, offering the specified interface and having the given persistent
- * ID.
- *
- * @param bundle
- * the bundle in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param pid
- * the persistent ID of the searched service.
- * @return a service provided by the specified bundle, offering the
- * specified interface and having the given persistent ID.
- */
- public static ServiceReference getServiceReferenceByPID(Bundle bundle,
- String itf, String pid) {
- String filter = "(" + "service.pid" + "=" + pid + ")";
- ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
- if (refs == null) {
- return null;
- } else if (refs.length == 1) {
- return refs[0];
- } else {
- throw new IllegalStateException(
- "A service lookup by PID returned several providers ("
- + refs.length + ")" + " for " + itf + " with pid="
- + pid);
- }
- }
-
-
-
- /**
- * Returns the service reference of all the services provided in the
- * specified bundle, offering the specified interface and matching the given
- * filter.
- *
- * @param bundle
- * the bundle in which services are searched.
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return all the service references provided in the specified bundle,
- * offering the specified interface and matching the given filter.
- * If no service matches, an empty array is returned.
- */
- public static ServiceReference[] getServiceReferences(Bundle bundle,
- String itf, String filter) {
- ServiceReference[] refs = null;
- try {
- // Get all the service references
- refs = bundle.getBundleContext().getServiceReferences(itf, filter);
- } catch (InvalidSyntaxException e) {
- throw new IllegalArgumentException(
- "Cannot get service references: " + e.getMessage());
- }
- if (refs == null) {
- return new ServiceReference[0];
- } else {
- return refs;
- }
- }
-
-
-
- /**
- * Returns the service object of a service provided by the local bundle,
- * offering the specified interface and matching the given filter.
- *
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return the service object provided by the local bundle, offering the
- * specified interface and matching the given filter.
- */
- public Object getServiceObject(String itf, String filter) {
- ServiceReference ref = getServiceReference(itf, filter);
- if (ref != null) {
- references.add(ref);
- return context.getService(ref);
- } else {
- return null;
- }
- }
-
-
- /**
- * Returns the service object associated with this service
- * reference.
+ /**
+ * Returns the service reference of the service provided by the specified
+ * bundle, offering the specified interface and having the given persistent
+ * ID.
*
- * @param ref
- * service reference
- * @return the service object.
+ * @param bundle the bundle from which the service is searched.
+ * @param itf the interface provided by the searched service.
+ * @param pid the persistent ID of the searched service.
+ * @return a service provided by the specified bundle, offering the
+ * specified interface and having the given persistent ID.
*/
- public Object getServiceObject(ServiceReference ref) {
+ public static ServiceReference getServiceReferenceByPID(Bundle bundle,
+ String itf, String pid) {
+ String filter = "(" + "service.pid" + "=" + pid + ")";
+ ServiceReference[] refs = getServiceReferences(bundle, itf, filter);
+ if (refs == null) {
+ return null;
+ } else if (refs.length == 1) {
+ return refs[0];
+ } else {
+ throw new IllegalStateException(
+ "A service lookup by PID returned several providers ("
+ + refs.length + ")" + " for " + itf + " with pid="
+ + pid);
+ }
+ }
+
+ /**
+ * Returns the service reference of all the services provided in the
+ * specified bundle, offering the specified interface and matching the given
+ * filter.
+ *
+ * @param bundle the bundle from which services are searched.
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
+ * @return all the service references provided in the specified bundle,
+ * offering the specified interface and matching the given filter.
+ * If no service matches, an empty array is returned.
+ */
+ public static ServiceReference[] getServiceReferences(Bundle bundle,
+ String itf, String filter) {
+ ServiceReference[] refs = null;
+ try {
+ // Get all the service references
+ refs = bundle.getBundleContext().getServiceReferences(itf, filter);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException(
+ "Cannot get service references: " + e.getMessage());
+ }
+ if (refs == null) {
+ return new ServiceReference[0];
+ } else {
+ return refs;
+ }
+ }
+
+ /**
+ * Returns the service object of a service provided by the local bundle,
+ * offering the specified interface and matching the given filter.
+ *
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
+ * @return the service object provided by the local bundle, offering the
+ * specified interface and matching the given filter.
+ */
+ public Object getServiceObject(String itf, String filter) {
+ ServiceReference ref = getServiceReference(itf, filter);
if (ref != null) {
- references.add(ref);
+ m_references.add(ref);
return context.getService(ref);
} else {
return null;
}
}
- /**
- * Returns the service objects of the services provided by the local
- * bundle, offering the specified interface and matching the given filter.
- *
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return the service objects provided by the local bundle, offering
- * the specified interface and matching the given filter.
- */
- public Object[] getServiceObjects(String itf, String filter) {
- ServiceReference[] refs = getServiceReferences(itf, filter);
+ /**
+ * Returns the service object associated with this service reference.
+ *
+ * @param ref service reference
+ * @return the service object.
+ */
+ public Object getServiceObject(ServiceReference ref) {
+ if (ref != null) {
+ m_references.add(ref);
+ return context.getService(ref);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the service objects of the services provided by the local bundle,
+ * offering the specified interface and matching the given filter.
+ *
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
+ * @return the service objects provided by the local bundle, offering the
+ * specified interface and matching the given filter.
+ */
+ public Object[] getServiceObjects(String itf, String filter) {
+ ServiceReference[] refs = getServiceReferences(itf, filter);
if (refs != null) {
Object[] list = new Object[refs.length];
for (int i = 0; i < refs.length; i++) {
- references.add(refs[i]);
+ m_references.add(refs[i]);
list[i] = context.getService(refs[i]);
}
return list;
@@ -472,69 +569,59 @@
}
}
- /**
- * Returns the service reference of a service provided by the local
- * bundle, offering the specified interface and matching the given filter.
- *
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return a service reference provided by the local bundle, offering
- * the specified interface and matching the given filter. If no
- * service is found, {@code null} is returned.
- */
- public ServiceReference getServiceReference(String itf, String filter) {
- return getServiceReference(context.getBundle(), itf, filter);
- }
-
- /**
- * Returns the service reference of a service provided
- * offering the specified interface.
+ /**
+ * Returns the service reference of a service provided by the local bundle,
+ * offering the specified interface and matching the given filter.
*
- * @param itf
- * the interface provided by the searched service.
- * @return a service reference provided by the local bundle, offering
- * the specified interface and matching the given filter. If no
- * service is found, {@code null} is returned.
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
+ * @return a service reference provided by the local bundle, offering the
+ * specified interface and matching the given filter. If no service
+ * is found, {@code null} is returned.
+ */
+ public ServiceReference getServiceReference(String itf, String filter) {
+ return getServiceReference(context.getBundle(), itf, filter);
+ }
+
+ /**
+ * Returns the service reference of a service provided offering the
+ * specified interface.
+ *
+ * @param itf the interface provided by the searched service.
+ * @return a service reference provided by the local bundle, offering the
+ * specified interface and matching the given filter. If no service
+ * is found, {@code null} is returned.
*/
public ServiceReference getServiceReference(String itf) {
return getServiceReference(context.getBundle(), itf, null);
}
- /**
- * Returns the service reference of the service provided by the local
- * bundle, offering the specified interface and having the given persistent
- * ID.
- *
- * @param itf
- * the interface provided by the searched service.
- * @param pid
- * the persistent ID of the searched service.
- * @return a service provided by the local bundle, offering the
- * specified interface and having the given persistent ID.
- */
- public ServiceReference getServiceReferenceByPID(String itf, String pid) {
- return getServiceReferenceByPID(context.getBundle(), itf, pid);
- }
+ /**
+ * Returns the service reference of the service provided by the local
+ * bundle, offering the specified interface and having the given persistent
+ * ID.
+ *
+ * @param itf the interface provided by the searched service.
+ * @param pid the persistent ID of the searched service.
+ * @return a service provided by the local bundle, offering the specified
+ * interface and having the given persistent ID.
+ */
+ public ServiceReference getServiceReferenceByPID(String itf, String pid) {
+ return getServiceReferenceByPID(context.getBundle(), itf, pid);
+ }
- /**
- * Returns the service reference of all the services provided in the
- * local bundle, offering the specified interface and matching the given
- * filter.
- *
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
- * @return all the service references provided in the local bundle,
- * offering the specified interface and matching the given filter.
- * If no service matches, an empty array is returned.
- */
- public ServiceReference[] getServiceReferences(String itf, String filter) {
- return getServiceReferences(context.getBundle(), itf, filter);
- }
-
-
+ /**
+ * Returns the service reference of all the services provided in the local
+ * bundle, offering the specified interface and matching the given filter.
+ *
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
+ * @return all the service references provided in the local bundle, offering
+ * the specified interface and matching the given filter. If no
+ * service matches, an empty array is returned.
+ */
+ public ServiceReference[] getServiceReferences(String itf, String filter) {
+ return getServiceReferences(context.getBundle(), itf, filter);
+ }
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java
index 8e7795a..581c14a 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/OSGiTestSuite.java
@@ -32,38 +32,71 @@
*/
public class OSGiTestSuite extends TestSuite {
- protected BundleContext context;
+ /**
+ * The bundle context of the bundle containing
+ * the test suite.
+ */
+ protected BundleContext m_context;
+ /**
+ * Creates a OSGiTestSuite.
+ * @param clazz the class
+ * @param bc the bundle context
+ * @see TestSuite#TestSuite(Class)
+ */
public OSGiTestSuite(Class clazz, BundleContext bc) {
super(clazz);
- context = bc;
- }
-
- public OSGiTestSuite(BundleContext bc) {
- super();
- context = bc;
- }
-
- public OSGiTestSuite(String name, BundleContext bc) {
- super(name);
- context = bc;
- }
-
- public OSGiTestSuite(Class clazz, String name, BundleContext bc) {
- super(clazz, name);
- context = bc;
- }
-
- public void setBundleContext(BundleContext bc) {
- context = bc;
+ m_context = bc;
}
/**
- * Adds the tests from the given class to the suite
+ * Creates a OSGiTestSuite.
+ * @param bc the bundle context
+ * @see TestSuite#TestSuite()
+ */
+ public OSGiTestSuite(BundleContext bc) {
+ super();
+ m_context = bc;
+ }
+
+ /**
+ * Creates a OSGiTestSuite.
+ * @param name the name
+ * @param bc the bundle context
+ * @see TestSuite#TestSuite(String)
+ */
+ public OSGiTestSuite(String name, BundleContext bc) {
+ super(name);
+ m_context = bc;
+ }
+
+ /**
+ * Creates a OSGiTestSuite.
+ * @param clazz the class
+ * @param name the name
+ * @param bc the bundle context
+ * @see TestSuite#TestSuite(Class, String)
+ */
+ public OSGiTestSuite(Class clazz, String name, BundleContext bc) {
+ super(clazz, name);
+ m_context = bc;
+ }
+
+ /**
+ * Set the bundle context.
+ * @param bc the bundle context to use.
+ */
+ public void setBundleContext(BundleContext bc) {
+ m_context = bc;
+ }
+
+ /**
+ * Adds the tests from the given class to the suite.
+ * @param testClass the class to add
*/
public void addTestSuite(Class testClass) {
if (OSGiTestCase.class.isAssignableFrom(testClass)) {
- addTest(new OSGiTestSuite(testClass, context));
+ addTest(new OSGiTestSuite(testClass, m_context));
} else if (TestCase.class.isAssignableFrom(testClass)) {
addTest(new TestSuite(testClass));
} else {
@@ -71,12 +104,19 @@
}
}
+ /**
+ * Executes the given {@link Test} with the
+ * given {@link TestResult}.
+ * @param test the test
+ * @param result the test result.
+ * @see junit.framework.TestSuite#runTest(junit.framework.Test, junit.framework.TestResult)
+ */
public void runTest(Test test, TestResult result) {
if (test instanceof OSGiTestSuite) {
- ((OSGiTestSuite) test).context = context;
+ ((OSGiTestSuite) test).m_context = m_context;
test.run(result);
} else if (test instanceof OSGiTestCase) {
- ((OSGiTestCase) test).context = context;
+ ((OSGiTestCase) test).setBundleContext(m_context);
test.run(result);
} else {
test.run(result);
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
index 697a4c2..791fcfd 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/helpers/IPOJOHelper.java
@@ -29,6 +29,7 @@
import org.apache.felix.ipojo.HandlerFactory;
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.junit4osgi.Helper;
import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManifestMetadataParser;
@@ -39,47 +40,74 @@
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ManagedServiceFactory;
-public class IPOJOHelper {
-
- private BundleContext context;
- private OSGiTestCase testcase;
-
-
- private List instances;
-
+/**
+ * iPOJO Helper.
+ * This helper helps getting {@link Factory}, and managing
+ * {@link ComponentInstance}.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class IPOJOHelper extends Helper {
+
+ /**
+ * The bundle context.
+ */
+ private BundleContext m_context;
+ /**
+ * The test case.
+ */
+ private OSGiTestCase m_testcase;
+
+ /**
+ * List of instances.
+ */
+ private List m_instances;
+
+ /**
+ * Creates a IPOJOHelper.
+ * @param tc the OSGi Test Case
+ */
public IPOJOHelper(OSGiTestCase tc) {
- testcase = tc;
- context = testcase.getBundleContext();
- instances = new ArrayList();
+ super(tc);
+ m_testcase = tc;
+ m_context = m_testcase.getBundleContext();
+ m_instances = new ArrayList();
}
-
+
+ /**
+ * Disposes created instances.
+ * @see org.apache.felix.ipojo.junit4osgi.Helper#dispose()
+ */
public void dispose() {
- for (int i = 0; i < instances.size(); i++) {
- ((ComponentInstance) instances.get(i)).dispose();
+ for (int i = 0; i < m_instances.size(); i++) {
+ ((ComponentInstance) m_instances.get(i)).dispose();
}
- instances.clear();
+ m_instances.clear();
}
-
+
+ /**
+ * Gets a created instance from the instance name.
+ * @param name the instance name.
+ * @return the created {@link ComponentInstance} or <code>null</code>
+ * if the instance was not created during the session.
+ */
public ComponentInstance getInstanceByName(String name) {
- for (int i = 0; i < instances.size(); i++) {
- if (((ComponentInstance) instances.get(i)).getInstanceName().equals(name)) {
- return (ComponentInstance) instances.get(i);
+ for (int i = 0; i < m_instances.size(); i++) {
+ if (((ComponentInstance) m_instances.get(i)).getInstanceName()
+ .equals(name)) {
+ return (ComponentInstance) m_instances.get(i);
}
}
return null;
}
-
+
/**
* Creates a new component instance with the given name (and empty
* configuration), from the factory specified in the given bundle.
*
- * @param bundle
- * the bundle in which the component factory is defined.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * bundle.
- * @param instanceName
- * the name of the component instance to create.
+ * @param bundle the bundle from which the component factory is defined.
+ * @param factoryName the name of the component factory, defined in the
+ * specified bundle.
+ * @param instanceName the name of the component instance to create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(Bundle bundle,
@@ -96,13 +124,11 @@
* Creates a new component instance with the given configuration, from the
* factory specified in the given bundle.
*
- * @param bundle
- * the bundle in which the component factory is defined.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * bundle.
- * @param configuration
- * the configuration of the component instance to create.
+ * @param bundle the bundle from which the component factory is defined.
+ * @param factoryName the name of the component factory, defined in the
+ * specified bundle.
+ * @param configuration the configuration of the component instance to
+ * create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(Bundle bundle,
@@ -123,8 +149,8 @@
return fact.createComponentInstance(configuration);
} catch (Exception e) {
throw new IllegalArgumentException(
- "Cannot create the component instance with the given configuration:" +
- e.getMessage());
+ "Cannot create the component instance with the given configuration:"
+ + e.getMessage());
}
}
@@ -132,15 +158,11 @@
* Creates a new component instance with the given name and configuration,
* from the factory specified in the given bundle.
*
- * @param bundle
- * the bundle in which the component factory is defined.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * bundle.
- * @param instanceName
- * the name of the component instance to create.
- * @param configuration
- * the configuration of the instance to create.
+ * @param bundle the bundle from which the component factory is defined.
+ * @param factoryName the name of the component factory, defined in the
+ * specified bundle.
+ * @param instanceName the name of the component instance to create.
+ * @param configuration the configuration of the instance to create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(Bundle bundle,
@@ -156,14 +178,11 @@
* Creates a new component instance with the given name (and an empty
* configuration), from the factory specified in the given service context.
*
- * @param serviceContext
- * the service context in which the component factory service is
- * registered.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * service context.
- * @param instanceName
- * the name of the component instance to create.
+ * @param serviceContext the service context in which the component factory
+ * service is registered.
+ * @param factoryName the name of the component factory, defined in the
+ * specified service context.
+ * @param instanceName the name of the component instance to create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(
@@ -182,14 +201,11 @@
* Creates a new component instance with the given name and configuration,
* from the factory specified in the given service context.
*
- * @param serviceContext
- * the service context in which the component factory service is
- * registered.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * service context.
- * @param configuration
- * the configuration of the instance to create.
+ * @param serviceContext the service context in which the component factory
+ * service is registered.
+ * @param factoryName the name of the component factory, defined in the
+ * specified service context.
+ * @param configuration the configuration of the instance to create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(
@@ -210,8 +226,8 @@
return fact.createComponentInstance(configuration);
} catch (Exception e) {
throw new IllegalArgumentException(
- "Cannot create the component instance with the given configuration: " +
- e.getMessage());
+ "Cannot create the component instance with the given configuration: "
+ + e.getMessage());
}
}
@@ -219,16 +235,12 @@
* Creates a new component instance with the given name and configuration,
* from the factory specified in the given service context.
*
- * @param serviceContext
- * the service context in which the component factory service is
- * registered.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * service context.
- * @param instanceName
- * the name of the component instance to create.
- * @param configuration
- * the configuration of the instance to create.
+ * @param serviceContext the service context in which the component factory
+ * service is registered.
+ * @param factoryName the name of the component factory, defined in the
+ * specified service context.
+ * @param instanceName the name of the component instance to create.
+ * @param configuration the configuration of the instance to create.
* @return the newly created component instance.
*/
public static ComponentInstance createComponentInstance(
@@ -241,23 +253,21 @@
return createComponentInstance(serviceContext, factoryName,
configuration);
}
-
+
/**
* Creates a new component instance with the given name (and empty
* configuration), from the factory specified in the local bundle.
*
- * @param factoryName
- * the name of the component factory, defined in the local
- * bundle.
- * @param instanceName
- * the name of the component instance to create.
+ * @param factoryName the name of the component factory, defined in the
+ * local bundle.
+ * @param instanceName the name of the component instance to create.
* @return the newly created component instance.
*/
public ComponentInstance createComponentInstance(String factoryName,
String instanceName) {
- ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
- instanceName);
- instances.add(ci);
+ ComponentInstance ci = createComponentInstance(m_context.getBundle(),
+ factoryName, instanceName);
+ m_instances.add(ci);
return ci;
}
@@ -265,32 +275,32 @@
* Creates a new component instance with the given configuration, from the
* factory specified in the local bundle.
*
- * @param factoryName
- * the name of the component factory, in the local bundle.
- * @param configuration
- * the configuration of the component instance to create.
+ * @param factoryName the name of the component factory, in the local
+ * bundle.
+ * @param configuration the configuration of the component instance to
+ * create.
* @return the newly created component instance.
*/
public ComponentInstance createComponentInstance(String factoryName,
Dictionary configuration) {
- ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
- configuration);
- instances.add(ci);
+ ComponentInstance ci = createComponentInstance(m_context.getBundle(),
+ factoryName, configuration);
+ m_instances.add(ci);
return ci;
}
-
+
/**
- * Creates a new component instance with no configuration, from the
- * factory specified in the local bundle.
+ * Creates a new component instance with no configuration, from the factory
+ * specified in the local bundle.
*
- * @param factoryName
- * the name of the component factory, in the local bundle.
+ * @param factoryName the name of the component factory, in the local
+ * bundle.
* @return the newly created component instance.
*/
public ComponentInstance createComponentInstance(String factoryName) {
- ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
- (Dictionary) null);
- instances.add(ci);
+ ComponentInstance ci = createComponentInstance(m_context.getBundle(),
+ factoryName, (Dictionary) null);
+ m_instances.add(ci);
return ci;
}
@@ -298,68 +308,58 @@
* Creates a new component instance with the given name and configuration,
* from the factory specified in the given bundle.
*
- * @param bundle
- * the bundle in which the component factory is defined.
- * @param factoryName
- * the name of the component factory, defined in the specified
- * bundle.
- * @param instanceName
- * the name of the component instance to create.
- * @param configuration
- * the configuration of the instance to create.
+ * @param factoryName the name of the component factory, defined in the
+ * specified bundle.
+ * @param instanceName the name of the component instance to create.
+ * @param configuration the configuration of the instance to create.
* @return the newly created component instance.
*/
public ComponentInstance createComponentInstance(String factoryName,
String instanceName, Dictionary configuration) {
- ComponentInstance ci = createComponentInstance(context.getBundle(), factoryName,
- instanceName, configuration);
- instances.add(ci);
+ ComponentInstance ci = createComponentInstance(m_context.getBundle(),
+ factoryName, instanceName, configuration);
+ m_instances.add(ci);
return ci;
}
/**
* Returns the component factory with the given name in the local bundle.
*
- * @param factoryName
- * the name of the factory to retrieve.
+ * @param factoryName the name of the factory to retrieve.
* @return the component factory with the given name in the local bundle, or
* {@code null} if not found.
*/
public Factory getFactory(String factoryName) {
- return getFactory(context.getBundle(), factoryName);
+ return getFactory(m_context.getBundle(), factoryName);
}
/**
* Returns the handler factory with the given name in the local bundle.
*
- * @param factoryName
- * the name of the handler factory to retrieve.
+ * @param factoryName the name of the handler factory to retrieve.
* @return the handler factory with the given name in the local bundle, or
* {@code null} if not found.
*/
public HandlerFactory getHandlerFactory(String factoryName) {
- return getHandlerFactory(context.getBundle(), factoryName);
+ return getHandlerFactory(m_context.getBundle(), factoryName);
}
/**
* Returns the metadata description of the component defined in this bundle.
*
- * @param component
- * the name of the locally defined component.
+ * @param component the name of the locally defined component.
* @return the metadata description of the component with the given name,
* defined in this given bundle, or {@code null} if not found.
*/
public Element getMetadata(String component) {
- return getMetadata(context.getBundle(), component);
+ return getMetadata(m_context.getBundle(), component);
}
-
+
/**
* Returns the component factory with the given name in the given bundle.
*
- * @param bundle
- * the bundle in which the component factory is defined.
- * @param factoryName
- * the name of the defined factory.
+ * @param bundle the bundle from which the component factory is defined.
+ * @param factoryName the name of the defined factory.
* @return the component factory with the given name in the given bundle, or
* {@code null} if not found.
*/
@@ -371,7 +371,7 @@
Factory.class.getName(),
"(factory.name=" + factoryName + ")");
if (refs != null) {
- return ((Factory) bundle.getBundleContext().getService(refs[0]));
+ return (Factory) bundle.getBundleContext().getService(refs[0]);
}
// Factory not found...
@@ -379,7 +379,8 @@
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(
- "Cannot get the component factory services: " + e.getMessage());
+ "Cannot get the component factory services: "
+ + e.getMessage());
}
}
@@ -387,10 +388,9 @@
* Returns the component factory with the given name, registered in the
* given service context.
*
- * @param serviceContext
- * the service context in which the factory service is defined.
- * @param factoryName
- * the name of the factory.
+ * @param serviceContext the service context in which the factory service is
+ * defined.
+ * @param factoryName the name of the factory.
* @return the component factory with the given name, registered in the
* given service context.
*/
@@ -403,7 +403,7 @@
refs = serviceContext.getServiceReferences(Factory.class.getName(),
"(factory.name=" + factoryName + ")");
if (refs != null) {
- return ((Factory) serviceContext.getService(refs[0]));
+ return (Factory) serviceContext.getService(refs[0]);
}
return null;
@@ -417,10 +417,8 @@
/**
* Returns the handler factory with the given name in the given bundle.
*
- * @param bundle
- * the bundle in which the handler factory is defined.
- * @param factoryName
- * the name of the handler factory to retrieve.
+ * @param bundle the bundle from which the handler factory is defined.
+ * @param factoryName the name of the handler factory to retrieve.
* @return the handler factory with the given name in the given bundle, or
* {@code null} if not found.
*/
@@ -442,7 +440,8 @@
return null;
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(
- "Cannot get the handler factory services: " + e.getMessage());
+ "Cannot get the handler factory services: "
+ + e.getMessage());
}
}
@@ -450,10 +449,8 @@
* Returns the metadata description of the component with the given name,
* defined in the given bundle.
*
- * @param bundle
- * the bundle in which the component is defined.
- * @param component
- * the name of the defined component.
+ * @param bundle the bundle from which the component is defined.
+ * @param component the name of the defined component.
* @return the metadata description of the component with the given name,
* defined in the given bundle, or {@code null} if not found.
*/
@@ -493,18 +490,16 @@
+ bundle.getSymbolicName() + "): " + e.getMessage());
}
}
-
+
/**
* Returns the service object of a service registered in the specified
* service context, offering the specified interface and matching the given
* filter.
*
- * @param serviceContext
- * the service context in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
+ * @param serviceContext the service context in which the service is
+ * searched.
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
* @return the service object provided by the specified bundle, offering the
* specified interface and matching the given filter.
*/
@@ -517,18 +512,15 @@
return null;
}
}
-
+
/**
* Returns the service objects of the services registered in the specified
* service context, offering the specified interface and matching the given
* filter.
*
- * @param serviceContext
- * the service context in which services are searched.
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
+ * @param serviceContext the service context in which services are searched.
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
* @return the service objects provided by the specified bundle, offering
* the specified interface and matching the given filter.
*/
@@ -546,18 +538,15 @@
return new Object[0];
}
}
-
+
/**
* Returns the service reference of a service registered in the specified
* service context, offering the specified interface and matching the given
* filter.
*
- * @param serviceContext
- * the service context in which services are searched.
- * @param itf
- * the interface provided by the searched service.
- * @param filter
- * an additional filter (can be {@code null}).
+ * @param serviceContext the service context in which services are searched.
+ * @param itf the interface provided by the searched service.
+ * @param filter an additional filter (can be {@code null}).
* @return a service reference registered in the specified service context,
* offering the specified interface and matching the given filter.
* If no service is found, {@code null} is returned.
@@ -573,18 +562,15 @@
return null;
}
}
-
+
/**
* Returns the service reference of the service registered in the specified
* service context, offering the specified interface and having the given
* persistent ID.
*
- * @param serviceContext
- * the service context in which services are searched.
- * @param itf
- * the interface provided by the searched service.
- * @param pid
- * the persistent ID of the searched service.
+ * @param serviceContext the service context in which services are searched.
+ * @param itf the interface provided by the searched service.
+ * @param pid the persistent ID of the searched service.
* @return a service registered in the specified service context, offering
* the specified interface and having the given persistent ID.
*/
@@ -604,18 +590,15 @@
+ pid);
}
}
-
+
/**
* Returns the service reference of all the services registered in the
* specified service context, offering the specified interface and matching
* the given filter.
*
- * @param serviceContext
- * the service context in which services are searched.
- * @param itf
- * the interface provided by the searched services.
- * @param filter
- * an additional filter (can be {@code null}).
+ * @param serviceContext the service context in which services are searched.
+ * @param itf the interface provided by the searched services.
+ * @param filter an additional filter (can be {@code null}).
* @return all the service references registered in the specified service
* context, offering the specified interface and matching the given
* filter. If no service matches, an empty array is returned.
@@ -637,18 +620,14 @@
}
}
-
/**
* Returns the service reference of a service registered in the specified
* service context, offering the specified interface and having the given
* name.
*
- * @param serviceContext
- * the service context in which services are searched.
- * @param itf
- * the interface provided by the searched service.
- * @param name
- * the name of the searched service.
+ * @param serviceContext the service context in which services are searched.
+ * @param itf the interface provided by the searched service.
+ * @param name the name of the searched service.
* @return a service registered in the specified service context, offering
* the specified interface and having the given name.
*/
@@ -665,56 +644,54 @@
}
return getServiceReference(serviceContext, itf, filter);
}
-
+
/**
* Checks the availability of a service inside the given service context.
* @param sc the service context
* @param itf the service interface to found
* @return <code>true</code> if the service is available in the service
- * context, <code>false</code> otherwise.
+ * context, <code>false</code> otherwise.
*/
public static boolean isServiceAvailable(ServiceContext sc, String itf) {
ServiceReference ref = getServiceReference(sc, itf, null);
return ref != null;
}
-
/**
* Checks the availability of a service inside the given service context.
* @param sc the service context
* @param itf the service interface to found
* @param name the service provider name
* @return <code>true</code> if the service is available in the service
- * context, <code>false</code> otherwise.
+ * context, <code>false</code> otherwise.
*/
- public static boolean isServiceAvailableByName(ServiceContext sc, String itf, String name) {
+ public static boolean isServiceAvailableByName(ServiceContext sc,
+ String itf, String name) {
ServiceReference ref = getServiceReferenceByName(sc, itf, name);
return ref != null;
}
-
+
/**
* Checks the availability of a service inside the given service context.
* @param sc the service context
* @param itf the service interface to found
* @param pid the pid of the service
* @return <code>true</code> if the service is available in the service
- * context, <code>false</code> otherwise.
+ * context, <code>false</code> otherwise.
*/
- public static boolean isServiceAvailableByPID(ServiceContext sc, String itf, String pid) {
+ public static boolean isServiceAvailableByPID(ServiceContext sc,
+ String itf, String pid) {
ServiceReference ref = getServiceReferenceByPID(sc, itf, pid);
return ref != null;
}
-
+
/**
* Returns the service reference of a service provided by the specified
* bundle, offering the specified interface and having the given name.
*
- * @param bundle
- * the bundle in which the service is searched.
- * @param itf
- * the interface provided by the searched service.
- * @param name
- * the name of the searched service.
+ * @param bundle the bundle from which the service is searched.
+ * @param itf the interface provided by the searched service.
+ * @param name the name of the searched service.
* @return a service provided by the specified bundle, offering the
* specified interface and having the given name.
*/
@@ -731,33 +708,30 @@
}
return OSGiTestCase.getServiceReference(bundle, itf, filter);
}
-
+
/**
- * Returns the service reference of a service provided by the local
- * bundle, offering the specified interface and having the given name.
+ * Returns the service reference of a service provided by the local bundle,
+ * offering the specified interface and having the given name.
*
- * @param itf
- * the interface provided by the searched service.
- * @param name
- * the name of the searched service.
+ * @param itf the interface provided by the searched service.
+ * @param name the name of the searched service.
* @return a service provided by the specified bundle, offering the
* specified interface and having the given name.
*/
public ServiceReference getServiceReferenceByName(String itf, String name) {
- return getServiceReferenceByName(context.getBundle(), itf, name);
+ return getServiceReferenceByName(m_context.getBundle(), itf, name);
}
-
+
/**
* Checks if the service is available.
* @param itf the service interface
- * @param the service provider name
- * @return <code>true</code> if the service is available,
- * <code>false</code> otherwise.
+ * @param name the service provider name
+ * @return <code>true</code> if the service is available, <code>false</code>
+ * otherwise.
*/
public boolean isServiceAvailableByName(String itf, String name) {
ServiceReference ref = getServiceReferenceByName(itf, name);
return ref != null;
}
-
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
index 39ee95f..45c928e 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/JunitExtender.java
@@ -48,14 +48,34 @@
*/
public class JunitExtender implements OSGiJunitRunner {
+ /**
+ * Suite method name.
+ */
public static final String SUITE_METHODNAME = "suite";
+ /**
+ * List of found suites (Bundle-> List of Class).
+ */
private Map/*<Bundle, List<Class>>*/ m_suites = new HashMap/*<Bundle, List<Class>>*/();
+ /**
+ * The result printer.
+ * By default, prints result on {@link System#out}
+ */
private ResultPrinter m_printer = new ResultPrinter(System.out);
+ /**
+ * The log service used to log messages.
+ * If not provided, a default implementation
+ * printing messages on the console is used.
+ */
private LogService m_log;
+ /**
+ * A new matching bundle arrives.
+ * @param bundle the matching bundle
+ * @param header the looked header value
+ */
void onBundleArrival(Bundle bundle, String header) {
String[] tss = ParseUtils.split(header, ",");
for (int i = 0; i < tss.length; i++) {
@@ -71,6 +91,11 @@
}
}
+ /**
+ * Adds a test suite.
+ * @param bundle the bundle declaring the test suite.
+ * @param test the test class.
+ */
private synchronized void addTestSuite(Bundle bundle, Class/*<? extends Test>*/ test) {
List/*<Class>*/ list = (List) m_suites.get(bundle);
if (list == null) {
@@ -82,19 +107,37 @@
}
}
+ /**
+ * Removes the test suites provided by the given bundles.
+ * @param bundle the leaving bundles.
+ */
private synchronized void removeTestSuites(Bundle bundle) {
List list = (List) m_suites.remove(bundle);
m_log.log(LogService.LOG_INFO, "Unload test suites " + list);
}
+ /**
+ * A matching bundle is leaving.
+ * @param bundle the leaving bundle.
+ */
void onBundleDeparture(Bundle bundle) {
removeTestSuites(bundle);
}
+ /**
+ * Set the result printer.
+ * @param pw the stream to use.
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#setResultPrinter(java.io.PrintStream)
+ */
public void setResultPrinter(PrintStream pw) {
m_printer = new ResultPrinter(pw);
}
+ /**
+ * Runs tests.
+ * @return the list of {@link TestResult}
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#run()
+ */
public synchronized List/*<TestResult>*/ run() {
List/*<TestResult>*/ results = new ArrayList/*<TestResult>*/(m_suites.size());
Iterator/*<Entry<Bundle, List<Class>>>*/ it = m_suites.entrySet().iterator();
@@ -103,7 +146,7 @@
Bundle bundle = (Bundle) entry.getKey();
List/*<Class>*/ list = (List) m_suites.get(bundle);
for (int i = 0; i < list.size(); i++) {
- Test test = createTestFromClass((Class)list.get(i), bundle);
+ Test test = createTestFromClass((Class) list.get(i), bundle);
TestResult tr = doRun(test);
results.add(tr);
}
@@ -111,6 +154,11 @@
return results;
}
+ /**
+ * Internal methods executing tests.
+ * @param test the test to execute
+ * @return the result
+ */
private TestResult doRun(Test test) {
TestResult result = new TestResult();
result.addListener(m_printer);
@@ -125,6 +173,15 @@
return result;
}
+ /**
+ * Creates a {@link Test} object from the
+ * given class from the given bundle.
+ * This method creates {@link OSGiTestCase} and
+ * {@link OSGiTestSuite} when required.
+ * @param clazz the class
+ * @param bundle the bundle
+ * @return the resulting Test object.
+ */
private Test createTestFromClass(Class/*<?>*/ clazz, Bundle bundle) {
Method suiteMethod = null;
boolean bc = false;
@@ -171,6 +228,11 @@
return test;
}
+ /**
+ * Gets the list of {@link Test}.
+ * @return the list of {@link Test}
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#getTests()
+ */
public synchronized List/*<Test>*/ getTests() {
List/*<Test>*/ results = new ArrayList/*<Test>*/();
Iterator/*<Entry<Bundle, List<Class>>>*/ it = m_suites.entrySet().iterator();
@@ -186,10 +248,23 @@
return results;
}
+ /**
+ * Runs the given tests.
+ * @param test the test to execute
+ * @return the result
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#run(junit.framework.Test)
+ */
public TestResult run(Test test) {
return doRun(test);
}
+ /**
+ * Gets the list of {@link Test} from the bundle (specified
+ * by using the bundle id).
+ * @param bundleId the bundle id
+ * @return the list of {@link Test} declared in this bundle.
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#getTests(long)
+ */
public synchronized List/*<Test>*/ getTests(long bundleId) {
Iterator/*<Entry<Bundle, List<Class>>>*/ it = m_suites.entrySet().iterator();
while (it.hasNext()) {
@@ -208,6 +283,13 @@
return null;
}
+ /**
+ * Runs the tests declared in the bundle
+ * (specified by the bundle id).
+ * @param bundleId the bundle id
+ * @return the List of {@link TestResult}
+ * @see org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner#run(long)
+ */
public synchronized List/*<TestResult>*/ run(long bundleId) {
Iterator/*<Entry<Bundle, List<Class>>>*/ it = m_suites.entrySet().iterator();
while (it.hasNext()) {
@@ -227,15 +309,29 @@
return null;
}
+ /**
+ * Stop method.
+ * Clears test suites.
+ */
public synchronized void stopping() {
m_log.log(LogService.LOG_INFO, "Cleaning test suites ...");
m_suites.clear();
}
+ /**
+ * Start method.
+ */
public void starting() {
m_log.log(LogService.LOG_INFO, "Junit Extender starting ...");
}
+ /**
+ * Helper method analyzing the {@link Bundle} object
+ * to get the {@link BundleContext} object.
+ * @param bundle the Bundle
+ * @return the BundleContext of <code>null</code> if
+ * the BundleContext cannot be collected.
+ */
private BundleContext getBundleContext(Bundle bundle) {
if (bundle == null) { return null; }
@@ -288,10 +384,10 @@
try {
return (BundleContext) fields[i].get(bundle);
} catch (IllegalArgumentException e) {
- m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by reflecting on " + fields[i].getName(), e);
return null;
} catch (IllegalAccessException e) {
- m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by invoking " + meth.getName(), e);
+ m_log.log(LogService.LOG_ERROR, "Cannot get the BundleContext by reflecting on " + fields[i].getName(), e);
return null;
}
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java
index 1da168a..71afd82 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/LogServiceImpl.java
@@ -1,10 +1,39 @@
+/*
+ * 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.felix.ipojo.junit4osgi.impl;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
+/**
+ * Log Service default implementation.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
public class LogServiceImpl implements LogService {
+ /**
+ * Creates a message.
+ * @param level the log level
+ * @param msg the message
+ * @param exception the thrown exception
+ * @return the computed message
+ */
private String computeLogMessage(int level, String msg, Throwable exception) {
String message = null;
switch (level) {
@@ -20,6 +49,8 @@
case LogService.LOG_WARNING:
message = "[WARNING] " + msg;
break;
+ default:
+ break;
}
if (exception != null) {
@@ -29,18 +60,46 @@
return message;
}
+ /**
+ * Logs a message.
+ * @param arg0 the log level
+ * @param arg1 the message
+ * @see org.osgi.service.log.LogService#log(int, java.lang.String)
+ */
public void log(int arg0, String arg1) {
System.err.println(computeLogMessage(arg0, arg1, null));
}
+ /**
+ * Logs a message.
+ * @param arg0 the log level
+ * @param arg1 the message
+ * @param arg2 the thrown exception
+ * @see org.osgi.service.log.LogService#log(int, java.lang.String)
+ */
public void log(int arg0, String arg1, Throwable arg2) {
System.err.println(computeLogMessage(arg0, arg1, arg2));
}
+ /**
+ * Logs a message.
+ * @param arg0 the service reference
+ * @param arg1 the log level
+ * @param arg2 the message
+ * @see org.osgi.service.log.LogService#log(ServiceReference, int, String)
+ */
public void log(ServiceReference arg0, int arg1, String arg2) {
System.err.println(computeLogMessage(arg1, arg2, null));
}
+ /**
+ * Logs a message.
+ * @param arg0 the service reference
+ * @param arg1 the log level
+ * @param arg2 the message
+ * @param arg3 the thrown exception
+ * @see org.osgi.service.log.LogService#log(ServiceReference, int, String, Throwable)
+ */
public void log(ServiceReference arg0, int arg1, String arg2, Throwable arg3) {
System.err.println(computeLogMessage(arg1, arg2, arg3));
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java
index 2acb056..906658b 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/impl/ResultPrinter.java
@@ -34,18 +34,29 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class ResultPrinter implements TestListener {
- PrintStream fWriter;
+ /**
+ * the writer.
+ */
+ PrintStream m_fWriter;
- int fColumn = 0;
+ /**
+ * The column .
+ */
+ int m_fColumn = 0;
+ /**
+ * Creates a ResultPrinter.
+ * @param writer the printer
+ */
public ResultPrinter(PrintStream writer) {
- fWriter = writer;
+ m_fWriter = writer;
}
- /*
- * API for use by textui.TestRunner
+ /**
+ * Prints the result.
+ * @param result the test result
+ * @param runTime the test duration
*/
-
synchronized void print(TestResult result, long runTime) {
printHeader(runTime);
printErrors(result);
@@ -53,6 +64,9 @@
printFooter(result);
}
+ /**
+ * Prints message wiating for prompt.
+ */
void printWaitPrompt() {
getWriter().println();
getWriter().println("<RETURN> to continue");
@@ -62,46 +76,86 @@
* Internal methods
*/
+ /**
+ * Prints the result header.
+ * @param runTime the test execution duration
+ */
protected void printHeader(long runTime) {
getWriter().println();
getWriter().println("Time: " + elapsedTimeAsString(runTime));
}
+ /**
+ * Prints the errors.
+ * @param result the test result
+ */
protected void printErrors(TestResult result) {
printDefects(result.errors(), result.errorCount(), "error");
}
+ /**
+ * Prints failures.
+ * @param result the test result
+ */
protected void printFailures(TestResult result) {
printDefects(result.failures(), result.failureCount(), "failure");
}
+ /**
+ * Prints failures.
+ * @param booBoos the failures
+ * @param count the number of failures
+ * @param type the type
+ */
protected void printDefects(Enumeration/*<TestFailure>*/ booBoos, int count, String type) {
- if (count == 0)
+ if (count == 0) {
return;
- if (count == 1)
+ }
+
+ if (count == 1) {
getWriter().println("There was " + count + " " + type + ":");
- else
+ } else {
getWriter().println("There were " + count + " " + type + "s:");
+ }
+
for (int i = 1; booBoos.hasMoreElements(); i++) {
printDefect((TestFailure) booBoos.nextElement(), i);
}
}
+ /**
+ * Prints a failure.
+ * @param booBoo the failure
+ * @param count the count
+ */
public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
printDefectHeader(booBoo, count);
printDefectTrace(booBoo);
}
+ /**
+ * Prints defect header.
+ * @param booBoo the failure
+ * @param count the count
+ */
protected void printDefectHeader(TestFailure booBoo, int count) {
// I feel like making this a println, then adding a line giving the throwable a chance to print something
// before we get to the stack trace.
getWriter().print(count + ") " + booBoo.failedTest());
}
+ /**
+ * Prints the stack trace.
+ * @param booBoo the failure
+ */
protected void printDefectTrace(TestFailure booBoo) {
getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
}
+ /**
+ * Prints the footer.
+ * @param result the test result.
+ */
protected void printFooter(TestResult result) {
if (result.wasSuccessful()) {
getWriter().println();
@@ -117,17 +171,22 @@
}
/**
- * Returns the formatted string of the elapsed time. Duplicated from BaseTestRunner. Fix it.
+ * Returns the formatted string of the elapsed time.
+ * @param runTime the elapsed time
+ * @return the elapsed time.
*/
protected String elapsedTimeAsString(long runTime) {
return NumberFormat.getInstance().format((double) runTime / 1000);
}
public PrintStream getWriter() {
- return fWriter;
+ return m_fWriter;
}
/**
+ * Adds an error.
+ * @param test the test in error.
+ * @param t the thrown error
* @see junit.framework.TestListener#addError(Test, Throwable)
*/
public void addError(Test test, Throwable t) {
@@ -135,6 +194,9 @@
}
/**
+ * Adds a failure.
+ * @param test the failing test.
+ * @param t the thrown failure
* @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
*/
public void addFailure(Test test, AssertionFailedError t) {
@@ -142,19 +204,23 @@
}
/**
+ * A test ends.
+ * (do nothing)
+ * @param test the ending test
* @see junit.framework.TestListener#endTest(Test)
*/
- public void endTest(Test test) {
- }
+ public void endTest(Test test) { }
/**
+ * A test starts.
+ * @param test the starting test
* @see junit.framework.TestListener#startTest(Test)
*/
public void startTest(Test test) {
getWriter().print(".");
- if (fColumn++ >= 40) {
+ if (m_fColumn++ >= 40) {
getWriter().println();
- fColumn = 0;
+ m_fColumn = 0;
}
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java
index 2ee139e..9d59e00 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestCase.java
@@ -26,9 +26,12 @@
*/
public class TestOSGiTestCase extends OSGiTestCase {
+ /**
+ * Test.
+ */
public void test1() {
System.out.println("Test BC");
- assertNotNull("Test bundle context", context);
+ assertNotNull("Test bundle context", getContext());
}
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java
index c68f37c..746a017 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestOSGiTestSuite.java
@@ -30,6 +30,11 @@
*/
public class TestOSGiTestSuite extends TestSuite {
+ /**
+ * Suite method.
+ * @param bc the bundle context
+ * @return the Test Suite.
+ */
public static Test suite(BundleContext bc) {
TestSuite ts = new TestSuite();
ts.setName("Test OSGi suite() method");
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java
index 0e1527b..c2f0ae4 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestCase.java
@@ -26,12 +26,24 @@
*/
public class TestTestCase extends TestCase {
+ /**
+ * test1.
+ */
public void test1() { }
+ /**
+ * test2.
+ */
public void test2() { }
+ /**
+ * test3.
+ */
public void test3() { }
+ /**
+ * test4.
+ */
public void test4() { }
}
diff --git a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java
index 6bd1bf1..d559ed9 100644
--- a/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java
+++ b/ipojo/examples/junit4osgi/junit4osgi/src/main/java/org/apache/felix/ipojo/junit4osgi/test/TestTestSuite.java
@@ -27,6 +27,10 @@
*/
public class TestTestSuite extends TestSuite {
+ /**
+ * Suite method.
+ * @return the test suite.
+ */
public static Test suite() {
TestSuite ts = new TestSuite();
ts.setName("Test suite() method");
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/LICENSE b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/NOTICE b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/NOTICE
new file mode 100644
index 0000000..34f9403
--- /dev/null
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/NOTICE
@@ -0,0 +1,17 @@
+Apache Felix iPOJO junit4osgi Maven Plugin
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
index a1798d6..729d27d 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
@@ -19,7 +19,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.felix.ipojo.junit4osgi</groupId>
+ <groupId>org.apache.felix</groupId>
<artifactId>maven-junit4osgi-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1.0-SNAPSHOT</version>
@@ -73,9 +73,35 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>ipojo.examples</groupId>
+ <groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <configLocation>http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml</configLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
index a7a8078..d98b48a 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -6,9 +6,9 @@
* 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
@@ -41,37 +41,37 @@
/**
* The list of artifact containing bundles for the junit4osgi framework.
*/
- private List artifacts;
+ private List m_artifacts;
/**
* The current maven project.
*/
- private MavenProject project;
+ private MavenProject m_project;
/**
- * Flag enabling/disbling the deployment of the current
+ * Flag enabling/disabling the deployment of the current
* project artifact.
*/
- private boolean deployCurrent;
+ private boolean m_deployCurrent;
/**
* List of bundle URLs to install.
*/
- private List bundles;
+ private List m_bundles;
/**
- * Creates a Installer
+ * Creates a Installer.
* @param artifacts the list of artifact containing bundles for the junit4osgi framework.
* @param bundles the list of bundle URLs to install
* @param project the current maven project
* @param deployCurrentArtifact flag enabling/disabling the deployment of the current project artifact
*/
public Installer(List artifacts, List bundles, MavenProject project, boolean deployCurrentArtifact) {
- this.artifacts = artifacts;
- this.project = project;
- deployCurrent = deployCurrentArtifact;
- this.bundles = bundles;
+ this.m_artifacts = artifacts;
+ this.m_project = project;
+ m_deployCurrent = deployCurrentArtifact;
+ this.m_bundles = bundles;
}
/**
@@ -109,11 +109,12 @@
/**
* Installs and Starts required bundles.
+ * @param context the bundle context used to deploy bundles.
* @throws BundleException when a bundle cannot be installed or started correctly
*/
private void deployBundles(BundleContext context) throws BundleException {
- for (int i = 0; i < bundles.size(); i++) {
- URL url = (URL) bundles.get(i);
+ for (int i = 0; i < m_bundles.size(); i++) {
+ URL url = (URL) m_bundles.get(i);
Bundle bundle = context.installBundle(url.toString());
bundle.start();
}
@@ -126,8 +127,8 @@
* be found.
*/
private URL getUrlByArtifactId(String id) {
- for (int i = 0; i < artifacts.size(); i++) {
- Artifact artifact = (Artifact) artifacts.get(i);
+ for (int i = 0; i < m_artifacts.size(); i++) {
+ Artifact artifact = (Artifact) m_artifacts.get(i);
if (artifact.getArtifactId().equals(id)) {
try {
return artifact.getFile().toURL();
@@ -145,12 +146,12 @@
* @throws BundleException when the bundle cannot be installed or started correctly.
*/
private void deployProjectArtifact(BundleContext context)
- throws BundleException {
- if (!deployCurrent) {
+ throws BundleException {
+ if (!m_deployCurrent) {
return;
}
- File file = project.getArtifact().getFile();
+ File file = m_project.getArtifact().getFile();
if (file.exists()) {
URL url = null;
try {
@@ -193,4 +194,4 @@
// Do nothing.
}
-}
\ No newline at end of file
+}
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
index 6af90e8..ce1f378 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -6,9 +6,9 @@
* 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
@@ -16,21 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.ipojo.junit4osgi.plugin;/*
-
- *
- * 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.apache.felix.ipojo.junit4osgi.plugin;
import java.io.File;
import java.io.PrintStream;
@@ -81,68 +67,98 @@
* @required
* @readonly
*/
- private MavenProject project;
+ private MavenProject m_project;
- /** @parameter expression="${plugin.artifacts}" */
- private java.util.List pluginArtifacts;
+ /**
+ * Dependencies of the current plugin.
+ * @parameter expression="${plugin.artifacts}"
+ */
+ private java.util.List m_pluginArtifacts;
/**
* Base directory where all reports are written to.
*
* @parameter expression="${project.build.directory}/junit4osgi-reports"
*/
- private File reportsDirectory;
+ private File m_reportsDirectory;
/**
* Base directory where all reports are written to.
*
* @parameter expression="${project.build.directory}"
*/
- private File targetDir;
+ private File m_targetDir;
/**
- * Must the current artifact be deployed?.
+ * Must the current artifact be deployed?
*
* @parameter expression="${deployProjectArtifact}" default-value="false"
*/
- private boolean deployProjectArtifact;
+ private boolean m_deployProjectArtifact;
/**
- * Required bundles
+ * Required bundles.
*
* @parameter expression="${bundles}"
*/
- private ArrayList bundles;
-
- int total;
- int totalFailures;
- int totalErrors;
-
- List errors = new ArrayList();
- List failures = new ArrayList();
- List results = new ArrayList();
+ private ArrayList m_bundles;
/**
- * Log Service exposed by the plugin framework.
+ * Number of executed test case.
*/
- private LogServiceImpl logService;
+ private int m_total;
+
+ /**
+ * Number of failing test case.
+ */
+ private int m_totalFailures;
+
+ /**
+ * Number of test case in error .
+ */
+ private int m_totalErrors;
+
+ /**
+ * Test results in error.
+ */
+ private List m_errors = new ArrayList();
+
+ /**
+ * Failing test results.
+ */
+ private List m_failures = new ArrayList();
+
+ /**
+ * Test results.
+ */
+ private List m_results = new ArrayList();
+
+ /**
+ * Log Service exposed by the plug-in framework.
+ */
+ private LogServiceImpl m_logService;
+ /**
+ * Executes the plug-in.
+ * @throws MojoFailureException when the test execution failed.
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
public void execute() throws MojoFailureException {
List bundles = parseBundleList();
bundles.addAll(getTestBundle());
List activators = new ArrayList();
- logService = new LogServiceImpl();
- activators.add(logService);
- activators.add(new Installer(pluginArtifacts, bundles, project, deployProjectArtifact));
+ m_logService = new LogServiceImpl();
+ activators.add(m_logService);
+ activators.add(new Installer(m_pluginArtifacts, bundles, m_project, m_deployProjectArtifact));
Map map = new HashMap();
map.put("felix.systembundle.activators", activators);
map.put("org.osgi.framework.storage.clean", "onFirstInit");
map.put("ipojo.log.level", "WARNING");
map.put("org.osgi.framework.bootdelegation", "junit.framework, org.osgi.service.log");
- map.put("org.osgi.framework.storage", targetDir.getAbsolutePath() + "/felix-cache");
+ map.put("org.osgi.framework.storage", m_targetDir.getAbsolutePath() + "/felix-cache");
System.out.println("");
@@ -170,19 +186,30 @@
getLog().error(e);
}
- if (totalErrors > 0 || totalFailures > 0) {
- throw new MojoFailureException("There are test failures. \n\n" +
- "Please refer to " + reportsDirectory.getAbsolutePath() +
- " for the individual test results.");
+ if (m_totalErrors > 0 || m_totalFailures > 0) {
+ throw new MojoFailureException("There are test failures. \n\n"
+ + "Please refer to " + m_reportsDirectory.getAbsolutePath()
+ + " for the individual test results.");
}
}
+ /**
+ * Waits for stability:
+ * <ul>
+ * <li>all bundles are activated
+ * <li>service count is stable
+ * </ul>
+ * If the stability can't be reached after a specified time,
+ * the method throws a {@link MojoFailureException}.
+ * @param context the bundle context
+ * @throws MojoFailureException when the stability can't be reach after a several attempts.
+ */
private void waitForStability(BundleContext context) throws MojoFailureException {
// Wait for bundle initialization.
boolean bundleStability = getBundleStability(context);
int count = 0;
- while(!bundleStability && count < 500) {
+ while (!bundleStability && count < 500) {
try {
Thread.sleep(5);
} catch (InterruptedException e) {
@@ -200,15 +227,16 @@
boolean serviceStability = false;
count = 0;
- int count1 = 0, count2 = 0;
- while(! serviceStability && count < 500) {
+ int count1 = 0;
+ int count2 = 0;
+ while (! serviceStability && count < 500) {
try {
ServiceReference[] refs = context.getServiceReferences(null, null);
count1 = refs.length;
Thread.sleep(500);
refs = context.getServiceReferences(null, null);
count2 = refs.length;
- serviceStability = (count1 == count2);
+ serviceStability = count1 == count2;
} catch (Exception e) {
getLog().error(e);
serviceStability = false;
@@ -225,6 +253,11 @@
}
+ /**
+ * Are bundle stables.
+ * @param bc the bundle context
+ * @return <code>true</code> if every bundles are activated.
+ */
private boolean getBundleStability(BundleContext bc) {
boolean stability = true;
Bundle[] bundles = bc.getBundles();
@@ -234,30 +267,39 @@
return stability;
}
+ /**
+ * Computes the URL list of bundles to install from
+ * the <code>bundles</code> parameter.
+ * @return the list of url of bundles to install.
+ */
private List parseBundleList() {
List toDeploy = new ArrayList();
- if (bundles == null) {
+ if (m_bundles == null) {
return toDeploy;
}
- for (int i = 0; i < bundles.size(); i++) {
- String bundle = (String) bundles.get(i);
+ for (int i = 0; i < m_bundles.size(); i++) {
+ String bundle = (String) m_bundles.get(i);
try {
URL url = new URL(bundle);
toDeploy.add(url);
} catch (MalformedURLException e) {
- // Not a valid url,
- getLog().error(bundle + " is not a valid url, bundle ignored");
-
+ // Not a valid url,
+ getLog().error(bundle + " is not a valid url, bundle ignored");
}
}
return toDeploy;
}
+ /**
+ * Computes the URL list of bundles to install from
+ * <code>test</code> scoped dependencies.
+ * @return the list of url of bundles to install.
+ */
private List getTestBundle() {
List toDeploy = new ArrayList();
- Set dependencies = project.getDependencyArtifacts();
+ Set dependencies = m_project.getDependencyArtifacts();
for (Iterator artifactIterator = dependencies.iterator(); artifactIterator.hasNext();) {
Artifact artifact = (Artifact) artifactIterator.next();
if (Artifact.SCOPE_TEST.equals(artifact.getScope())) { // Select scope=test.
@@ -275,6 +317,12 @@
return toDeploy;
}
+ /**
+ * Waits until the {@link OSGiJunitRunner} service
+ * is published.
+ * @param bc the bundle context
+ * @return the {@link OSGiJunitRunner} service object.
+ */
private Object waitForRunnerService(BundleContext bc) {
ServiceReference ref = bc.getServiceReference(org.apache.felix.ipojo.junit4osgi.OSGiJunitRunner.class.getName());
int count = 0;
@@ -293,6 +341,11 @@
return null;
}
+ /**
+ * Executes tests by using reflection.
+ * @param runner the {@link OSGiJunitRunner} service object
+ * @param bc the bundle context
+ */
private void invokeRun(Object runner, BundleContext bc) {
Method getTest;
@@ -301,39 +354,45 @@
List tests = (List) getTest.invoke(runner, new Object[0]);
Method run = getRunMethod(runner);
for (int i = 0; i < tests.size(); i++) {
- executeTest(runner, (Test) tests.get(i),run, bc);
+ executeTest(runner, (Test) tests.get(i), run, bc);
}
System.out.println("\nResults :");
- if (failures.size() > 0) {
+ if (m_failures.size() > 0) {
System.out.println("\nFailed tests:");
- for (int i = 0; i < failures.size(); i++) {
- TestResult tr = (TestResult) failures.get(i);
+ for (int i = 0; i < m_failures.size(); i++) {
+ TestResult tr = (TestResult) m_failures.get(i);
Enumeration e = tr.failures();
- while(e.hasMoreElements()) {
+ while (e.hasMoreElements()) {
TestFailure tf = (TestFailure) e.nextElement();
System.out.println(" " + tf.toString());
}
}
}
- if (failures.size() > 0) {
+ if (m_failures.size() > 0) {
System.out.println("\nTests in error:");
- for (int i = 0; i < errors.size(); i++) {
- TestResult tr = (TestResult) errors.get(i);
+ for (int i = 0; i < m_errors.size(); i++) {
+ TestResult tr = (TestResult) m_errors.get(i);
Enumeration e = tr.errors();
- while(e.hasMoreElements()) {
+ while (e.hasMoreElements()) {
TestFailure tf = (TestFailure) e.nextElement();
System.out.println(" " + tf.toString());
}
}
}
- System.out.println("\nTests run: " + total + ", Failures: " + totalFailures + ", Errors:" + totalErrors + "\n");
+ System.out.println("\nTests run: " + m_total + ", Failures: " + m_totalFailures + ", Errors:" + m_totalErrors + "\n");
} catch (Exception e) {
getLog().error(e);
}
}
+ /**
+ * Gets the {@link OSGiJunitRunner#run(long)} method from the
+ * {@link OSGiJunitRunner} service object.
+ * @param runner the {@link OSGiJunitRunner} service object.
+ * @return the Method object for the <code>run</code> method.
+ */
private Method getRunMethod(Object runner) {
Method[] methods = runner.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -347,6 +406,14 @@
return null;
}
+ /**
+ * Computes the name of the given test.
+ * This method calls the {@link TestCase#getName()}
+ * method by reflection. If no success, invokes the
+ * {@link Object#toString()} method.
+ * @param test the test object.
+ * @return the name of the given test.
+ */
private String getTestName(Object test) {
try {
Method getName = test.getClass().getMethod("getName", new Class[0]);
@@ -362,43 +429,69 @@
}
- private void executeTest(Object runner, Test test, Method run, BundleContext bc) {
+ /**
+ * Executes the given test.
+ * @param runner the {@link OSGiJunitRunner} service object
+ * @param test the test to run
+ * @param run the {@link OSGiJunitRunner#run(long)} method
+ * @param bc the bundle context
+ */
+ private void executeTest(Object runner, Test test, Method run,
+ BundleContext bc) {
try {
- XMLReport report = new XMLReport();
- String name = getTestName(test);
- System.out.println("Running " + name);
+ XMLReport report = new XMLReport();
+ String name = getTestName(test);
+ System.out.println("Running " + name);
- TestResult tr = new TestResult();
- tr.addListener(new ResultListener(report));
- test.run(tr);
- results.add(tr);
-
- if (tr.wasSuccessful()) {
- System.out.println("Tests run: " + tr.runCount() + ", Failures: " + tr.failureCount() + ", Errors: " + tr.errorCount() + ", Time elapsed: " + report.elapsedTimeAsString(report.endTime - report.endTime) + " sec");
- } else {
- System.out.println("Tests run: " + tr.runCount() + ", Failures: " + tr.failureCount() + ", Errors: " + tr.errorCount() + ", Time elapsed: " + report.elapsedTimeAsString(report.endTime - report.endTime) + " sec <<< FAILURE!");
- if (tr.errorCount() > 0) {
- errors.add(tr);
+ TestResult tr = new TestResult();
+ tr.addListener(new ResultListener(report));
+ test.run(tr);
+ m_results.add(tr);
+
+ if (tr.wasSuccessful()) {
+ System.out.println("Tests run: "
+ + tr.runCount()
+ + ", Failures: "
+ + tr.failureCount()
+ + ", Errors: "
+ + tr.errorCount()
+ + ", Time elapsed: "
+ + report.elapsedTimeAsString(report.m_endTime
+ - report.m_endTime) + " sec");
+ } else {
+ System.out.println("Tests run: "
+ + tr.runCount()
+ + ", Failures: "
+ + tr.failureCount()
+ + ", Errors: "
+ + tr.errorCount()
+ + ", Time elapsed: "
+ + report.elapsedTimeAsString(report.m_endTime
+ - report.m_endTime) + " sec <<< FAILURE!");
+ if (tr.errorCount() > 0) {
+ m_errors.add(tr);
+ }
+ if (tr.failureCount() > 0) {
+ m_failures.add(tr);
+ }
}
- if (tr.failureCount() > 0) {
- failures.add(tr);
- }
- }
-
- total += tr.runCount();
- totalFailures += tr.failureCount();
- totalErrors += tr.errorCount();
-
- report.generateReport(test, tr, reportsDirectory, bc);
-
+
+ m_total += tr.runCount();
+ m_totalFailures += tr.failureCount();
+ m_totalErrors += tr.errorCount();
+
+ report.generateReport(test, tr, m_reportsDirectory, bc);
+
} catch (Exception e) {
getLog().error(e);
}
-
-
-
+
}
+ /**
+ * Prints the bundle list.
+ * @param bc the bundle context.
+ */
public void dumpBundles(BundleContext bc) {
getLog().info("Bundles:");
Bundle[] bundles = bc.getBundles();
@@ -408,51 +501,99 @@
}
public LogServiceImpl getLogService() {
- return logService;
+ return m_logService;
}
private class ResultListener implements TestListener {
- private XMLReport report;
- private boolean abort;
+ /**
+ * The XML Report.
+ */
+ private XMLReport m_report;
- private PrintStream outBackup = System.out;
- private PrintStream errBackup = System.err;
+ /**
+ * Check if the test has failed or thrown an
+ * error.
+ */
+ private boolean m_abort;
- private StringOutputStream out = new StringOutputStream();
- private StringOutputStream err = new StringOutputStream();;
+ /**
+ * Backup of the {@link System#out} stream.
+ */
+ private PrintStream m_outBackup = System.out;
+ /**
+ * Backup of the {@link System#err} stream.
+ */
+ private PrintStream m_errBackup = System.err;
+
+ /**
+ * The output stream used during the test execution.
+ */
+ private StringOutputStream m_out = new StringOutputStream();
+
+ /**
+ * The error stream used during the test execution.
+ */
+ private StringOutputStream m_err = new StringOutputStream();;
+
+ /**
+ * Creates a ResultListener.
+ * @param report the XML report
+ */
public ResultListener(XMLReport report) {
- this.report = report;
+ this.m_report = report;
}
+ /**
+ * An error occurs during the test execution.
+ * @param test the test in error
+ * @param throwable the thrown error
+ * @see junit.framework.TestListener#addError(junit.framework.Test, java.lang.Throwable)
+ */
public void addError(Test test, Throwable throwable) {
- report.testError(test, throwable, out.toString(), err.toString(), getLogService().getLoggedMessages());
- abort = true;
+ m_report.testError(test, throwable, m_out.toString(), m_err.toString(), getLogService().getLoggedMessages());
+ m_abort = true;
}
+ /**
+ * An failure occurs during the test execution.
+ * @param test the failing test
+ * @param assertionfailederror the failure
+ * @see junit.framework.TestListener#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
+ */
public void addFailure(Test test,
AssertionFailedError assertionfailederror) {
- report.testFailed(test, assertionfailederror, out.toString(), err.toString(), getLogService().getLoggedMessages());
- abort = true;
+ m_report.testFailed(test, assertionfailederror, m_out.toString(), m_err.toString(), getLogService().getLoggedMessages());
+ m_abort = true;
}
+ /**
+ * The test ends.
+ * @param test the test
+ * @see junit.framework.TestListener#endTest(junit.framework.Test)
+ */
public void endTest(Test test) {
- if (!abort) {
- report.testSucceeded(test);
- }
- System.setErr(errBackup);
- System.setOut(outBackup);
- getLogService().reset();
+ if (!m_abort) {
+ m_report.testSucceeded(test);
+ }
+ System.setErr(m_errBackup);
+ System.setOut(m_outBackup);
+ getLogService().reset();
}
+ /**
+ * The test starts.
+ * @param test the test
+ * @see junit.framework.TestListener#startTest(junit.framework.Test)
+ */
public void startTest(Test test) {
- abort = false;
- report.testStarting();
- System.setErr(new PrintStream(err));
- System.setOut(new PrintStream(out));
+ m_abort = false;
+ m_report.testStarting();
+ System.setErr(new PrintStream(m_err));
+ System.setOut(new PrintStream(m_out));
getLogService().enableOutputStream();
}
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Report.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Report.java
index cbb8905..16ab48b 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Report.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Report.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -6,9 +6,9 @@
* 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
@@ -37,57 +37,57 @@
public class Report {
/**
- * Number of ran tests.
+ * New line constant.
*/
- protected int completedCount;
+ protected static final String NL = System.getProperty("line.separator");
/**
- * Number of errors
+ * Number of ran tests.
*/
- protected int errorsCount;
+ protected int m_completedCount;
+
+ /**
+ * Number of errors.
+ */
+ protected int m_errorsCount;
/**
- * Number of failures
+ * Number of failures.
*/
- protected int failuresCount;
+ protected int m_failuresCount;
/**
- * Failing tests.
- */
- private List failureSources = new ArrayList();
-
- /**
- * Tests in error
- */
- private List errorSources = new ArrayList();
-
- /**
* Time at the beginning of the test execution.
*/
- protected long startTime;
+ protected long m_startTime;
/**
* Time at the end of the test execution.
*/
- protected long endTime;
+ protected long m_endTime;
/**
+ * Failing tests.
+ */
+ private List m_failureSources = new ArrayList();
+
+ /**
+ * Tests in error.
+ */
+ private List m_errorSources = new ArrayList();
+
+ /**
* Double format.
*/
- private NumberFormat numberFormat = NumberFormat.getInstance( Locale.US );
+ private NumberFormat m_numberFormat = NumberFormat.getInstance(Locale.US);
/**
- * New line constant.
- */
- protected static final String NL = System.getProperty( "line.separator" );
-
- /**
* Gets failing tests.
* @return the list of failing tests.
*/
public List getFailureSources() {
- return this.failureSources;
+ return this.m_failureSources;
}
/**
@@ -95,14 +95,14 @@
* @return the list of test throwing unexpected exceptions
*/
public List getErrorSources() {
- return this.errorSources;
+ return this.m_errorSources;
}
/**
* Callback called when a test starts.
*/
public void testStarting() {
- startTime = System.currentTimeMillis();
+ m_startTime = System.currentTimeMillis();
}
/**
@@ -117,8 +117,8 @@
* @param test the test in error.
*/
public void testError(Test test) {
- ++errorsCount;
- errorSources.add(test.toString());
+ ++m_errorsCount;
+ m_errorSources.add(test.toString());
endTest();
}
@@ -127,8 +127,8 @@
* @param test the failing test.
*/
public void testFailed(Test test) {
- ++failuresCount;
- failureSources.add(test.toString());
+ ++m_failuresCount;
+ m_failureSources.add(test.toString());
endTest();
}
@@ -137,41 +137,41 @@
* This method handles common action when a test ends.
*/
private void endTest() {
- ++completedCount;
+ ++m_completedCount;
- endTime = System.currentTimeMillis();
+ m_endTime = System.currentTimeMillis();
- if (startTime == 0) {
- startTime = endTime;
+ if (m_startTime == 0) {
+ m_startTime = m_endTime;
}
}
public int getNumErrors() {
- return errorsCount;
+ return m_errorsCount;
}
public int getNumFailures() {
- return failuresCount;
+ return m_failuresCount;
}
public int getNumTests() {
- return completedCount;
+ return m_completedCount;
}
/**
* Reset the report.
*/
public void reset() {
- errorsCount = 0;
+ m_errorsCount = 0;
- failuresCount = 0;
+ m_failuresCount = 0;
- completedCount = 0;
+ m_completedCount = 0;
- this.failureSources = new ArrayList();
+ this.m_failureSources = new ArrayList();
- this.errorSources = new ArrayList();
+ this.m_errorSources = new ArrayList();
}
@@ -182,13 +182,14 @@
* @return the String displaying the elapsed time
*/
protected String elapsedTimeAsString(long runTime) {
- return numberFormat.format((double) runTime / 1000);
+ return m_numberFormat.format((double) runTime / 1000);
}
/**
- * Returns the stacktrace as String.
- * @param report ReportEntry object.
- * @return stacktrace as string.
+ * Returns the stack trace as String.
+ * @param test the test
+ * @param e the exception
+ * @return stack trace as string.
*/
protected String getStackTrace(Test test, Throwable e) {
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/StringOutputStream.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/StringOutputStream.java
index 60186cf..fa0a1f7 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/StringOutputStream.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/StringOutputStream.java
@@ -1,3 +1,21 @@
+/*
+ * 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.felix.ipojo.junit4osgi.plugin;
import java.io.OutputStream;
@@ -6,6 +24,7 @@
/**
* Provides an OutputStream to an internal String. Internally converts bytes to
* a Strings and stores them in an internal StringBuffer.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class StringOutputStream extends OutputStream implements Serializable {
@@ -17,14 +36,14 @@
/**
* The internal destination StringBuffer.
*/
- protected StringBuffer buf = null;
+ protected StringBuffer m_buffer = null;
/**
* Creates new StringOutputStream, makes a new internal StringBuffer.
*/
public StringOutputStream() {
super();
- buf = new StringBuffer();
+ m_buffer = new StringBuffer();
}
/**
@@ -34,14 +53,14 @@
* @return returns the content of the internal StringBuffer
*/
public String toString() {
- return buf.toString();
+ return m_buffer.toString();
}
/**
* Sets the internal StringBuffer to null.
*/
public void close() {
- buf = null;
+ m_buffer = null;
}
@@ -62,7 +81,7 @@
bytes[i] = b[off];
off++;
}
- buf.append(toCharArray(bytes));
+ m_buffer.append(toCharArray(bytes));
}
/**
@@ -71,7 +90,7 @@
* @param b the byte as an int to add
*/
public void write(int b) {
- buf.append((char) b);
+ m_buffer.append((char) b);
}
/**
@@ -80,11 +99,14 @@
* @param s the String to add
*/
public void write(String s) {
- buf.append(s);
+ m_buffer.append(s);
}
/**
* Converts byte array to char array.
+ * @param barr input byte array
+ * @return the char array corresponding to the
+ * given byte array
*/
public static char[] toCharArray(byte[] barr) {
if (barr == null) {
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
index 6d3a722..88e72ec 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -6,9 +6,9 @@
* 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
@@ -51,7 +51,7 @@
/**
* List of results.
*/
- private List results = new ArrayList();
+ private List m_results = new ArrayList();
/**
* A test ends successfully.
@@ -60,17 +60,20 @@
public void testSucceeded(Test test) {
super.testSucceeded();
- long runTime = this.endTime - this.startTime;
+ long runTime = this.m_endTime - this.m_startTime;
Xpp3Dom testCase = createTestElement(test, runTime);
- results.add(testCase);
+ m_results.add(testCase);
}
/**
* A test throws an unexpected errors.
* @param test the test in error
* @param e the thrown exception
+ * @param out the output messages printed during the test execution
+ * @param err the error messages printed during the test execution
+ * @param log the messages logged during the test execution
*/
public void testError(Test test, Throwable e, String out, String err, String log) {
super.testError(test);
@@ -82,6 +85,9 @@
* A test fails.
* @param test the failing test
* @param e the thrown failure
+ * @param out the output messages printed during the test execution
+ * @param err the error messages printed during the test execution
+ * @param log the messages logged during the test execution
*/
public void testFailed(Test test, Throwable e, String out, String err, String log) {
super.testFailed(test);
@@ -94,10 +100,13 @@
* @param test the test
* @param e the thrown error
* @param name type of failure ("error" or "failure")
+ * @param out the output messages printed during the test execution
+ * @param err the error messages printed during the test execution
+ * @param log the messages logged during the test execution
*/
private void writeTestProblems(Test test, Throwable e, String name, String out, String err, String log) {
- long runTime = endTime - startTime;
+ long runTime = m_endTime - m_startTime;
Xpp3Dom testCase = createTestElement(test, runTime);
@@ -115,8 +124,8 @@
element.setAttribute("message", message);
element.setAttribute("type",
- (stackTrace.indexOf(":") > -1 ? stackTrace.substring(0,
- stackTrace.indexOf(":")) : stackTrace));
+ stackTrace.indexOf(":") > -1 ? stackTrace.substring(0,
+ stackTrace.indexOf(":")) : stackTrace);
} else {
element.setAttribute("type", new StringTokenizer(stackTrace)
.nextToken());
@@ -127,13 +136,13 @@
element.setValue(stackTrace);
}
- addOutputStreamElement( out, "system-out", testCase );
+ addOutputStreamElement(out, "system-out", testCase);
- addOutputStreamElement( err, "system-err", testCase );
-
- addOutputStreamElement( log, "log-service", testCase );
+ addOutputStreamElement(err, "system-err", testCase);
- results.add(testCase);
+ addOutputStreamElement(log, "log-service", testCase);
+
+ m_results.add(testCase);
}
/**
@@ -146,7 +155,7 @@
*/
public void generateReport(Test test, TestResult tr, File reportsDirectory,
BundleContext bc) throws Exception {
- long runTime = this.endTime - this.startTime;
+ long runTime = this.m_endTime - this.m_startTime;
Xpp3Dom testSuite = createTestSuiteElement(test, runTime);
@@ -158,7 +167,7 @@
testSuite.setAttribute("failures", String.valueOf(tr.failureCount()));
- for (Iterator i = results.iterator(); i.hasNext();) {
+ for (Iterator i = m_results.iterator(); i.hasNext();) {
Xpp3Dom testcase = (Xpp3Dom) i.next();
testSuite.addChild(testcase);
}
@@ -183,9 +192,7 @@
throw new Exception("Unable to use UTF-8 encoding", e);
} catch (FileNotFoundException e) {
throw new Exception("Unable to create file: " + e.getMessage(), e);
- }
-
- finally {
+ } finally {
IOUtil.close(writer);
}
}
@@ -231,7 +238,7 @@
}
/**
- * Creates an XML element
+ * Creates an XML element.
* @param element the parent element
* @param name the name of the element to create
* @return the resulting XML tree.
@@ -294,6 +301,8 @@
case Bundle.UNINSTALLED:
state = "UNINSTALLED";
break;
+ default:
+ break;
}
Xpp3Dom bundle = createElement(buns, "bundle");
bundle.setAttribute("symbolic-name", sn);
@@ -302,6 +311,13 @@
}
+ /**
+ * Adds messages written during the test execution in the
+ * XML tree.
+ * @param stdOut the messages
+ * @param name the name of the stream (out, error, log)
+ * @param testCase the XML tree
+ */
private void addOutputStreamElement(String stdOut, String name,
Xpp3Dom testCase) {
if (stdOut != null && stdOut.trim().length() > 0) {
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/log/LogServiceImpl.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/log/LogServiceImpl.java
index aaa6fe0..bb795ac 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/log/LogServiceImpl.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/log/LogServiceImpl.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -6,9 +6,9 @@
* 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
@@ -35,25 +35,25 @@
/**
* Default output stream (not collected).
*/
- private StringOutputStream defaultStream;
+ private StringOutputStream m_defaultStream;
/**
* Collected output stream.
*/
- private StringOutputStream outputStream;
+ private StringOutputStream m_outputStream;
/**
* Creates the log service object.
*/
public LogServiceImpl() {
- defaultStream = new StringOutputStream();
+ m_defaultStream = new StringOutputStream();
}
/**
* Enables the log messages collection.
*/
public void enableOutputStream() {
- outputStream = new StringOutputStream();
+ m_outputStream = new StringOutputStream();
}
/**
@@ -61,14 +61,14 @@
* @return the String containing the logged messages.
*/
public String getLoggedMessages() {
- return outputStream.toString();
+ return m_outputStream.toString();
}
/**
* Re-initializes the collected message list.
*/
public void reset() {
- outputStream = null;
+ m_outputStream = null;
}
/**
@@ -138,6 +138,8 @@
case LogService.LOG_WARNING:
message = "[WARNING] " + msg;
break;
+ default:
+ break;
}
if (exception != null) {
@@ -152,10 +154,10 @@
* @param log the message
*/
public void write(String log) {
- if (outputStream != null) {
- outputStream.write(log);
+ if (m_outputStream != null) {
+ m_outputStream.write(log);
} else {
- defaultStream.write(log);
+ m_defaultStream.write(log);
}
}
diff --git a/ipojo/examples/junit4osgi/pom.xml b/ipojo/examples/junit4osgi/pom.xml
index 1dede45..5166221 100644
--- a/ipojo/examples/junit4osgi/pom.xml
+++ b/ipojo/examples/junit4osgi/pom.xml
@@ -18,8 +18,8 @@
-->
<project>
<modelVersion>4.0.0</modelVersion>
- <artifactId>Junit4Osgi</artifactId>
- <groupId>ipojo.examples</groupId>
+ <artifactId>Junit4OSGi</artifactId>
+ <groupId>org.apache.felix</groupId>
<version>1.1.0-SNAPSHOT</version>
<name>Apache Felix iPOJO Junit4OSGi</name>
<packaging>pom</packaging>
diff --git a/ipojo/examples/junit4osgi/swing-runner/LICENSE b/ipojo/examples/junit4osgi/swing-runner/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/ipojo/examples/junit4osgi/swing-runner/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/ipojo/examples/junit4osgi/swing-runner/NOTICE b/ipojo/examples/junit4osgi/swing-runner/NOTICE
new file mode 100644
index 0000000..b766c24
--- /dev/null
+++ b/ipojo/examples/junit4osgi/swing-runner/NOTICE
@@ -0,0 +1,17 @@
+Apache Felix iPOJO junit4osgi Swing Runner
+Copyright 2008 The Apache Software Foundation
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+III. License Summary
+- Apache License 2.0
diff --git a/ipojo/examples/junit4osgi/swing-runner/metadata.xml b/ipojo/examples/junit4osgi/swing-runner/metadata.xml
index 9251b6f..2a5a610 100644
--- a/ipojo/examples/junit4osgi/swing-runner/metadata.xml
+++ b/ipojo/examples/junit4osgi/swing-runner/metadata.xml
@@ -1,3 +1,21 @@
+<!--
+ 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.
+-->
<?xml version="1.0" encoding="UTF-8"?>
<iPOJO>
<component
diff --git a/ipojo/examples/junit4osgi/swing-runner/pom.xml b/ipojo/examples/junit4osgi/swing-runner/pom.xml
index fe9b18e..4931067 100644
--- a/ipojo/examples/junit4osgi/swing-runner/pom.xml
+++ b/ipojo/examples/junit4osgi/swing-runner/pom.xml
@@ -21,7 +21,7 @@
<packaging>bundle</packaging>
<name>Junit4Osgi-Swing-GUI</name>
<artifactId>org.apache.felix.ipojo.junit4osgi.swing-gui</artifactId>
- <groupId>ipojo.examples</groupId>
+ <groupId>org.apache.felix</groupId>
<version>1.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
@@ -30,61 +30,78 @@
<version>1.1.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.shell</artifactId>
- <version>1.0.2</version>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.3</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>
- iPOJO OSGi Junit Runner - Swing Gui
- </Bundle-Name>
- <Bundle-SymbolicName>
- ${pom.artifactId}
- </Bundle-SymbolicName>
- <Private-Package>
- org.apache.felix.ipojo.junit4osgi.command
- </Private-Package>
- <Import-Package>org.osgi.framework;version=1.3,*</Import-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- <configuration>
- <ignoreAnnotations>true</ignoreAnnotations>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name> iPOJO OSGi Junit Runner - Swing Gui</Bundle-Name>
+ <Bundle-SymbolicName> ${pom.artifactId}</Bundle-SymbolicName>
+ <Private-Package> org.apache.felix.ipojo.junit4osgi.command
+ </Private-Package>
+ <Import-Package>org.osgi.framework;version=1.3,*
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ <configuration>
+ <ignoreAnnotations>true</ignoreAnnotations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin
+ </artifactId>
+ <configuration>
+ <configLocation>
+ http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml
+ </configLocation>
+ <violationSeverity>error</violationSeverity>
+ </configuration>
+ </plugin>
+ </plugins>
+</build>
</project>
diff --git a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultCellRenderer.java b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultCellRenderer.java
index 680ad32..3370f1a 100644
--- a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultCellRenderer.java
+++ b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultCellRenderer.java
@@ -1,20 +1,3 @@
-/*
- * Copyright 2008 clement.
- *
- * 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.
- * under the License.
- */
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -52,12 +35,23 @@
*/
private static final long serialVersionUID = 1L;
+ /**
+ * Renderer method.
+ * @param table the table
+ * @param value the value
+ * @param isSelected is the cell selected
+ * @param hasFocus has the cell the focus
+ * @param row the cell row
+ * @param column the cell column
+ * @return the resulting component
+ * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
+ */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
ResultTableModel results = (ResultTableModel) table.getModel();
String status = (String) results.getValueAt(row, column);
- if (status.equals(ResultTableModel.SUCESS)) {
+ if (status.equals(ResultTableModel.SUCCESS)) {
c.setForeground(Color.GREEN);
setToolTipText(results.getMessage(row, column));
}
diff --git a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultTableModel.java b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultTableModel.java
index 491f223..bf457ba 100644
--- a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultTableModel.java
+++ b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/ResultTableModel.java
@@ -35,51 +35,84 @@
*/
public class ResultTableModel extends AbstractTableModel {
- public static final String SUCESS = "success";
+ /**
+ * Success String.
+ */
+ public static final String SUCCESS = "success";
+ /**
+ * Failure String.
+ */
public static final String FAILURE = "failure";
+ /**
+ * Error String.
+ */
public static final String ERROR = "error";
+ /**
+ * UUDI.
+ */
private static final long serialVersionUID = 1L;
- private List<TestRecord> results = new ArrayList<TestRecord>();
+ /**
+ * List of results.
+ */
+ private List<TestRecord> m_results = new ArrayList<TestRecord>();
public int getRowCount() {
- return results.size();
+ return m_results.size();
}
public int getColumnCount() {
return 2;
}
+ /**
+ * Adds a failing test.
+ * @param t the test
+ * @param e the assertion error
+ */
public void addTest(Test t, AssertionFailedError e) {
TestRecord rec = new TestRecord(t, e);
- results.add(rec);
+ m_results.add(rec);
fireTableDataChanged();
}
+ /**
+ * Adds a test in error.
+ * @param t the test
+ * @param e the thrown error
+ */
public void addTest(Test t, Throwable e) {
TestRecord rec = new TestRecord(t, e);
- results.add(rec);
+ m_results.add(rec);
fireTableDataChanged();
}
+ /**
+ * Adds a sucessfull test.
+ * @param t the test
+ */
public void addTest(Test t) {
if (!contains(t)) {
TestRecord rec = new TestRecord(t);
- results.add(rec);
+ m_results.add(rec);
fireTableDataChanged();
}
}
public int getTestCount() {
- return results.size();
+ return m_results.size();
}
+ /**
+ * Gets the number of success.
+ * @return the number of success
+ */
public int getSucess() {
int count = 0;
- for (TestRecord test : results) {
+ for (TestRecord test : m_results) {
if (test.m_wasSucessFull) {
count++;
}
@@ -87,19 +120,27 @@
return count;
}
+ /**
+ * Gets the number of errors.
+ * @return the number of errors
+ */
public int getErrors() {
int count = 0;
- for (TestRecord test : results) {
+ for (TestRecord test : m_results) {
if (test.m_error != null) {
count++;
}
}
return count;
}
-
+
+ /**
+ * Gets the number of failures.
+ * @return the number of failures
+ */
public int getFailures() {
int count = 0;
- for (TestRecord test : results) {
+ for (TestRecord test : m_results) {
if (test.m_failure != null) {
count++;
}
@@ -107,29 +148,51 @@
return count;
}
+
+ /**
+ * Does the result list contains the given test.
+ * @param t the test
+ * @return <code>true</code> if the list contains the test.
+ */
private boolean contains(Test t) {
- for (TestRecord test : results) {
+ for (TestRecord test : m_results) {
if (test.m_test.equals(t)) { return true; }
}
return false;
}
+ /**
+ * Clear the list.
+ */
public void clear() {
- results.clear();
+ m_results.clear();
fireTableDataChanged();
}
+ /**
+ * Get the Object placed in the JTable.
+ * @param rowIndex the row
+ * @param columnIndex the column
+ * @return the object
+ * @see javax.swing.table.TableModel#getValueAt(int, int)
+ */
public Object getValueAt(int rowIndex, int columnIndex) {
- if (columnIndex == 0) { return results.get(rowIndex).m_test; }
+ if (columnIndex == 0) { return m_results.get(rowIndex).m_test; }
if (columnIndex == 1) {
- TestRecord tr = results.get(rowIndex);
- if (tr.m_wasSucessFull) { return SUCESS; }
+ TestRecord tr = m_results.get(rowIndex);
+ if (tr.m_wasSucessFull) { return SUCCESS; }
if (tr.m_failure != null) { return FAILURE; }
if (tr.m_error != null) { return ERROR; }
}
return null;
}
+ /**
+ * Gets column names.
+ * @param column the column
+ * @return the column name
+ * @see javax.swing.table.AbstractTableModel#getColumnName(int)
+ */
public String getColumnName(int column) {
if (column == 0) { return "Test"; }
@@ -138,9 +201,15 @@
return null;
}
+ /**
+ * Gets the message.
+ * @param row the row
+ * @param column the column
+ * @return the message for this cell
+ */
public String getMessage(int row, int column) {
if (row == -1) { return null; }
- TestRecord rec = results.get(row);
+ TestRecord rec = m_results.get(row);
if (rec.m_wasSucessFull) { return "The test " + rec.m_test + " was executed sucessfully."; }
if (rec.m_failure != null) { return "The test " + rec.m_test + " has failed : \n" + rec.m_failure.getMessage(); }
if (rec.m_error != null) {
@@ -154,26 +223,52 @@
}
private class TestRecord {
+ /**
+ * Was the test successful?
+ */
private boolean m_wasSucessFull;
+ /**
+ * The test.
+ */
private Test m_test;
+ /**
+ * The failure.
+ */
private AssertionFailedError m_failure;
+ /**
+ * The error.
+ */
private Throwable m_error;
+ /**
+ * Creates a TestRecord.
+ * @param t the test
+ * @param e the failure
+ */
public TestRecord(Test t, AssertionFailedError e) {
m_test = t;
m_wasSucessFull = false;
m_failure = e;
}
+ /**
+ * Creates a TestRecord.
+ * @param t the test
+ * @param e the error
+ */
public TestRecord(Test t, Throwable e) {
m_test = t;
m_wasSucessFull = false;
m_error = e;
}
+ /**
+ * Creates a TestRecord.
+ * @param t the test
+ */
public TestRecord(Test t) {
m_test = t;
m_wasSucessFull = true;
diff --git a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.form b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.form
index 55cf564..5d5abba 100644
--- a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.form
+++ b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.form
@@ -1,3 +1,21 @@
+<!--
+ 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.
+-->
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
diff --git a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.java b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.java
index 82c4366..90eb523 100644
--- a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.java
+++ b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/SwingRunner.java
@@ -41,6 +41,9 @@
*/
public class SwingRunner extends javax.swing.JFrame implements BundleListener {
+ /**
+ * UUID.
+ */
private static final long serialVersionUID = 1L;
/**
@@ -96,17 +99,17 @@
m_progress.setIndeterminate(false);
m_progress.setMaximum(100);
m_progress.setValue(100);
-
+
TableColumn column = null;
for (int i = 0; i < m_resultTable.getColumnCount(); i++) {
column = m_resultTable.getColumnModel().getColumn(i);
if (i == 0) {
- column.setPreferredWidth(350); //first column is bigger
+ column.setPreferredWidth(350); // first column is bigger
} else {
column.setPreferredWidth(50);
column.setCellRenderer(new ResultCellRenderer());
+ }
}
-}
}
/**
@@ -120,6 +123,7 @@
/**
* Refresh the list of available test suites.
*/
+ @SuppressWarnings("unchecked")
private void refreshSuites() {
List<Test> list = m_runner.getTests();
TestListModel lm = (TestListModel) m_suiteList.getModel();
@@ -296,13 +300,13 @@
getContentPane().add(m_statusBar, gridBagConstraints);
pack();
- }// </editor-fold>//GEN-END:initComponents
+ } // </editor-fold>//GEN-END:initComponents
/**
* Execute button action.
* @param evt : event.
*/
- private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_executeButtonActionPerformed
+ private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_m_executeButtonActionPerformed
if (m_running) { return; }
// Collect selected test.
int[] indices = m_suiteList.getSelectedIndices();
@@ -313,26 +317,26 @@
}
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
executeTest(list);
- }//GEN-LAST:event_m_executeButtonActionPerformed
+ } //GEN-LAST:event_m_executeButtonActionPerformed
/**
* All button action.
* @param evt : event.
*/
- private void allButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_allButtonActionPerformed
+ private void allButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_m_allButtonActionPerformed
int max = m_suiteList.getModel().getSize();
int[] indices = new int[max];
for (int i = 0; i < max; i++) {
indices[i] = i;
}
m_suiteList.setSelectedIndices(indices);
- }//GEN-LAST:event_m_allButtonActionPerformed
+ } //GEN-LAST:event_m_allButtonActionPerformed
/**
* Listener on table click.
* @param evt : event.
*/
- private void resultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_m_resultTableMouseClicked
+ private void resultTableMouseClicked(java.awt.event.MouseEvent evt) { //GEN-FIRST:event_m_resultTableMouseClicked
Point p = evt.getPoint();
int row = m_resultTable.rowAtPoint(p);
int col = m_resultTable.columnAtPoint(p);
@@ -344,25 +348,25 @@
m_messageArea.setText(message);
m_resultDialog.setVisible(true);
}
- }//GEN-LAST:event_m_resultTableMouseClicked
+ } //GEN-LAST:event_m_resultTableMouseClicked
/**
* Ok button action.
* @param evt : event.
*/
- private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_okActionPerformed
+ private void okActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_m_okActionPerformed
m_resultDialog.setVisible(false);
setEnabled(true);
- }//GEN-LAST:event_m_okActionPerformed
+ } //GEN-LAST:event_m_okActionPerformed
/**
* Listener when the test report is closed.
* @param evt : event.
*/
- private void onDialogClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_onDialogClosed
+ private void onDialogClosed(java.awt.event.WindowEvent evt) { //GEN-FIRST:event_onDialogClosed
m_resultDialog.setVisible(false);
setEnabled(true);
- }//GEN-LAST:event_onDialogClosed
+ } //GEN-LAST:event_onDialogClosed
/**
* Execute method.
@@ -394,15 +398,19 @@
new Thread(thread).start();
}
- private void computeExecutedTest() {
+ /**
+ * Compute executed tests.
+ * (Status bar message)
+ */
+ private void computeExecutedTest() {
ResultTableModel results = (ResultTableModel) m_resultTable.getModel();
String m = " \t ";
- m+= results.getTestCount() + " tests executed / ";
- m+= results.getSucess() + " sucess / ";
- m+= results.getFailures() + " failures / ";
- m+= results.getErrors() + " errors ";
+ m += results.getTestCount() + " tests executed / ";
+ m += results.getSucess() + " sucess / ";
+ m += results.getFailures() + " failures / ";
+ m += results.getErrors() + " errors ";
m_executedResults.setText(m);
- }
+ }
private class MyTestListener implements junit.framework.TestListener {
/**
diff --git a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/TestListModel.java b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/TestListModel.java
index 4811c5e..3232dad 100644
--- a/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/TestListModel.java
+++ b/ipojo/examples/junit4osgi/swing-runner/src/main/java/org/apache/felix/ipojo/junit4osgi/command/TestListModel.java
@@ -29,39 +29,65 @@
*/
public class TestListModel extends AbstractListModel {
+ /**
+ * Id.
+ */
private static final long serialVersionUID = 1L;
- private List<TestRecord> list = new ArrayList<TestRecord>();
+ /**
+ * List of {@link TestRecord}.
+ */
+ private List<TestRecord> m_list = new ArrayList<TestRecord>();
+ /**
+ * Gets the element placed at the given index.
+ * @param index the index
+ * @return the element placed at the given index
+ * or <code>null</code> if no element at this index
+ * @see javax.swing.ListModel#getElementAt(int)
+ */
public Object getElementAt(int index) {
- if (index >= list.size()) {
+ if (index >= m_list.size()) {
return null;
} else {
- return list.get(index).name;
+ return m_list.get(index).m_name;
}
}
+ /**
+ * Gets the test object placed at the given index.
+ * @param index the index
+ * @return the test object placed at the given index
+ */
public Test getTestElementAt(int index) {
- return list.get(index).test;
+ return m_list.get(index).m_test;
}
+ /**
+ * Adds a test.
+ * @param test the test to add
+ */
public void addTest(Test test) {
- synchronized(this) {
+ synchronized (this) {
TestRecord tr = new TestRecord();
- tr.test = test;
- tr.name = test.toString();
- list.add(tr);
+ tr.m_test = test;
+ tr.m_name = test.toString();
+ m_list.add(tr);
}
- fireContentsChanged(this, list.size() - 1, list.size() - 1);
+ fireContentsChanged(this, m_list.size() - 1, m_list.size() - 1);
}
+ /**
+ * Removes a test.
+ * @param test the test to remove
+ */
public void removeTest(Test test) {
int index = 1;
- synchronized(this) {
- for (TestRecord t : list) {
- if (t.test.equals(test)) {
- index = list.indexOf(t);
- list.remove(t);
+ synchronized (this) {
+ for (TestRecord t : m_list) {
+ if (t.m_test.equals(test)) {
+ index = m_list.indexOf(t);
+ m_list.remove(t);
return;
}
}
@@ -72,18 +98,32 @@
}
}
+ /**
+ * Clears the list.
+ */
public void clear() {
- list.clear();
+ m_list.clear();
}
private class TestRecord {
- public Test test;
+ /**
+ * The test.
+ */
+ public Test m_test;
- public String name;
+ /**
+ * The test name.
+ */
+ public String m_name;
}
+ /**
+ * Gets the list size.
+ * @return the list size.
+ * @see javax.swing.ListModel#getSize()
+ */
public int getSize() {
- return list.size();
+ return m_list.size();
}
}