Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 96bed1c

Browse files
author
Constantino Cronemberger
committed
Test for ModelHelper
1 parent 12f8355 commit 96bed1c

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

core-server/src/main/java/org/glassfish/jersey/server/model/internal/ModelHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -46,7 +46,7 @@
4646
* Common model helper methods.
4747
*
4848
* @author Michal Gajdos (michal.gajdos at oracle.com)
49-
* @author Constantino Cronemberger (cocr at gft.com)
49+
* @author Constantino Cronemberger (ccronemberger at yahoo.com.br)
5050
*/
5151
public final class ModelHelper {
5252

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.server.model.internal;
41+
42+
import org.junit.Assert;
43+
import org.junit.Test;
44+
45+
import javax.ws.rs.Path;
46+
import java.lang.reflect.InvocationHandler;
47+
import java.lang.reflect.Method;
48+
import java.lang.reflect.Proxy;
49+
50+
/**
51+
* @author Constantino Cronemberger (ccronemberger at yahoo.com.br)
52+
*/
53+
public class ModelHelperTest {
54+
55+
@Test
56+
public void testClass() {
57+
Class cls = ModelHelper.getAnnotatedResourceClass(MyAnnotatedClass.class);
58+
Assert.assertSame(MyAnnotatedClass.class, cls);
59+
}
60+
61+
@Test
62+
public void testSubClass() {
63+
// Spring with CGLIB proxies creates sub-classes
64+
Object obj = new MyAnnotatedClass() {};
65+
Assert.assertNotSame(MyAnnotatedClass.class,obj.getClass());
66+
Class cls = ModelHelper.getAnnotatedResourceClass(obj.getClass());
67+
Assert.assertSame(MyAnnotatedClass.class, cls);
68+
}
69+
70+
@Test
71+
public void testProxyClass() throws Exception {
72+
// Spring can also create proxies for beans
73+
Object obj = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {MyServiceInterface.class}, new InvocationHandler() {
74+
@Override
75+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
76+
return null;
77+
}
78+
});
79+
Class cls = ModelHelper.getAnnotatedResourceClass(obj.getClass());
80+
Assert.assertSame(MyServiceInterface.class, cls);
81+
}
82+
83+
@Path("test")
84+
public static interface MyServiceInterface {}
85+
86+
@Path("test")
87+
public static class MyAnnotatedClass implements MyServiceInterface {}
88+
}

0 commit comments

Comments
 (0)