This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new c498f09 JUNEAU-194
c498f09 is described below
commit c498f09fdbffa4a1b4e440c6d7eb9ff1148fa06d
Author: JamesBognar <[email protected]>
AuthorDate: Tue Mar 10 18:54:51 2020 -0400
JUNEAU-194
Provide a simple Hyperlink bean.
---
juneau-doc/docs/ReleaseNotes/8.1.4.html | 2 +
.../apache/juneau/rest/helper/HyperlinkTest.java | 67 ++++++++++++++++++++++
.../org/apache/juneau/rest/helper/Hyperlink.java | 61 ++++++++++++++++++++
3 files changed, 130 insertions(+)
diff --git a/juneau-doc/docs/ReleaseNotes/8.1.4.html
b/juneau-doc/docs/ReleaseNotes/8.1.4.html
index 243c61d..cbb7676 100644
--- a/juneau-doc/docs/ReleaseNotes/8.1.4.html
+++ b/juneau-doc/docs/ReleaseNotes/8.1.4.html
@@ -136,6 +136,8 @@
{@link oajr.springboot.JuneauRestInitializer} now provides a
no-arg constructor so that it can be used in
the
<c><ja>@ConfigurationContext</ja>(initializers=JuneauRestInitializer.<jk>class</jk>)</c>
when unit testing
using <ja>@SpringBootTest</ja>.
+ <li>
+ New {@link oajr.helper.Hyperlink} class.
</ul>
<h5 class='topic w800'>juneau-rest-client</h5>
diff --git
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/HyperlinkTest.java
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/HyperlinkTest.java
new file mode 100644
index 0000000..83bfe4d
--- /dev/null
+++
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/HyperlinkTest.java
@@ -0,0 +1,67 @@
+//
***************************************************************************************************************************
+// * 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.juneau.rest.helper;
+
+import static org.junit.Assert.*;
+
+import java.util.*;
+
+import org.apache.juneau.rest.*;
+import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.mock2.*;
+import org.junit.*;
+import org.junit.runners.*;
+
+/**
+ * Tests the {@link Hyperlink} class.
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class HyperlinkTest {
+
+ @Rest
+ public static class A extends BasicRestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @RestMethod
+ public Hyperlink a01() {
+ return new Hyperlink("foo", "bar");
+ }
+
+ @RestMethod
+ public Hyperlink[] a02() {
+ return new Hyperlink[]{a01(),a01()};
+ }
+
+ @RestMethod
+ public Collection<Hyperlink> a03() {
+ return Arrays.asList(a02());
+ }
+ }
+
+ static MockRest a = MockRest.build(A.class);
+
+ @Test
+ public void a01_basic() throws Exception {
+ assertEquals("<a href=\"/foo\">bar</a>",
a.get("/a01").accept("text/html+stripped").execute().getBodyAsString());
+ }
+
+ @Test
+ public void a02_array() throws Exception {
+ assertEquals("<ul><li><a href=\"/foo\">bar</a></li><li><a
href=\"/foo\">bar</a></li></ul>",
a.get("/a02").accept("text/html+stripped").execute().getBodyAsString());
+ }
+
+ @Test
+ public void a03_collection() throws Exception {
+ assertEquals("<ul><li><a href=\"/foo\">bar</a></li><li><a
href=\"/foo\">bar</a></li></ul>",
a.get("/a03").accept("text/html+stripped").execute().getBodyAsString());
+ }
+}
\ No newline at end of file
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/helper/Hyperlink.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/helper/Hyperlink.java
new file mode 100644
index 0000000..55f5f16
--- /dev/null
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/helper/Hyperlink.java
@@ -0,0 +1,61 @@
+//
***************************************************************************************************************************
+// * 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.juneau.rest.helper;
+
+import org.apache.juneau.dto.html5.*;
+
+/**
+ * Defines a simple hyperlink class.
+ *
+ * <h5 class='figure'>Examples:</h5>
+ * <p class='bcode w800>
+ * <ja>@Rest</ja>
+ * <jk>public class</jk> MyRest <jk>extends</jk> BasicRestServlet {
+ *
+ * <jc>// Produces <a href="/foo">bar</a></jc>
+ * <ja>@RestMethod</ja>
+ * <jk>public</jk> Hyperlink a01() {
+ * <jk>return new</jk> Hyperlink(<js>"foo"</js>,
<js>"bar"</js>);
+ * }
+ *
+ * <jc>// Produces <ul><li><a
href="/foo">bar</a></li></ul></jc>
+ * <ja>@RestMethod</ja>
+ * <jk>public</jk> Hyperlink[] a02() {
+ * <jk>return new</jk> Hyperlink[]{a01()};
+ * }
+ *
+ * <jc>// Produces <ul><li><a
href="/foo">bar</a></li></ul></jc>
+ * <ja>@RestMethod</ja>
+ * <jk>public</jk> Collection<Hyperlink> a03() {
+ * <jk>return</jk> Arrays.<jsm>asList</jsm>(a02());
+ * }
+ * }
+ * </p>
+ */
+public class Hyperlink extends A {
+ /**
+ * Creates an empty {@link A} element.
+ */
+ public Hyperlink() {}
+
+ /**
+ * Creates an {@link A} element with the specified {@link
A#href(Object)} attribute and {@link A#children(Object[])}
+ * nodes.
+ *
+ * @param href The {@link A#href(Object)} attribute.
+ * @param children The {@link A#children(Object[])} nodes.
+ */
+ public Hyperlink(Object href, Object...children) {
+ super(href, children);
+ }
+}