-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3691 from ChristinaDsl/RESTEASY-3029
[RESTEASY-3029] Allow @Separator annotation at fields and methods
- Loading branch information
Showing
6 changed files
with
262 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...gration-tests/src/test/java/org/jboss/resteasy/test/core/spi/SeparatorAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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.jboss.resteasy.test.core.spi; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.Client; | ||
import jakarta.ws.rs.client.ClientBuilder; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.resteasy.spi.HttpResponseCodes; | ||
import org.jboss.resteasy.test.core.spi.resource.SeparatorAnnotationAsFieldTargetEndPoint; | ||
import org.jboss.resteasy.test.core.spi.resource.SeparatorAnnotationAsMethodTargetEndPoint; | ||
import org.jboss.resteasy.test.core.spi.resource.SeparatorAnnotationAsParameterTargetEndPoint; | ||
import org.jboss.resteasy.test.core.spi.resource.SeparatorAnnotationBeanParam; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @tpSubChapter Separator Annotation | ||
* @tpChapter Integration tests | ||
* @tpTestCaseDetails Testing Separator annotation, for each of its targets, see RESTEASY-3029 | ||
* @tpSince RESTEasy 6.3.0.Alpha1-SNAPSHOT | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class SeparatorAnnotationTest { | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
WebArchive war = TestUtil.prepareArchive(SeparatorAnnotationTest.class.getSimpleName()) | ||
.addClass(SeparatorAnnotationTest.class); | ||
return TestUtil.finishContainerPrepare(war, null, | ||
SeparatorAnnotationAsParameterTargetEndPoint.class, | ||
SeparatorAnnotationAsFieldTargetEndPoint.class, | ||
SeparatorAnnotationAsMethodTargetEndPoint.class, | ||
SeparatorAnnotationBeanParam.class); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, SeparatorAnnotationTest.class.getSimpleName()); | ||
} | ||
|
||
@Test | ||
public void testSeparatorAsParameterTarget() throws IOException { | ||
try (Client client = ClientBuilder.newClient()) { | ||
Response response = client | ||
.target(generateURL("/separator/parameter/1,2,3")) | ||
.request() | ||
.get(); | ||
|
||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
Assert.assertEquals("This is your sentence:123", response.readEntity(String.class)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSeparatorAsFieldTarget() throws IOException { | ||
try (Client client = ClientBuilder.newClient()) { | ||
Response response = client | ||
.target(generateURL("/separator/field/1,2,3")) | ||
.request() | ||
.get(); | ||
|
||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
Assert.assertEquals("This is your sentence:123", response.readEntity(String.class)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSeparatorAsMethodTarget() throws IOException { | ||
try (Client client = ClientBuilder.newClient()) { | ||
Response response = client | ||
.target(generateURL("/separator/method/1,2,3")) | ||
.request() | ||
.get(); | ||
|
||
Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus()); | ||
Assert.assertEquals("This is your sentence:123", response.readEntity(String.class)); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...a/org/jboss/resteasy/test/core/spi/resource/SeparatorAnnotationAsFieldTargetEndPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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.jboss.resteasy.test.core.spi.resource; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import org.jboss.resteasy.annotations.Separator; | ||
|
||
@Path("/separator/field/{ids}") | ||
public class SeparatorAnnotationAsFieldTargetEndPoint { | ||
@PathParam("ids") | ||
@Separator(",") | ||
private List<String> ids; | ||
|
||
@GET | ||
@Produces("text/plain") | ||
public String getSentence() { | ||
return "This is your sentence:" + String.join("", ids); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../org/jboss/resteasy/test/core/spi/resource/SeparatorAnnotationAsMethodTargetEndPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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.jboss.resteasy.test.core.spi.resource; | ||
|
||
import jakarta.ws.rs.BeanParam; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
@Path("/separator/method/{ids}") | ||
public class SeparatorAnnotationAsMethodTargetEndPoint { | ||
@GET | ||
@Produces("text/plain") | ||
public String getSentence(@BeanParam SeparatorAnnotationBeanParam resource) { | ||
return resource.toString(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...g/jboss/resteasy/test/core/spi/resource/SeparatorAnnotationAsParameterTargetEndPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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.jboss.resteasy.test.core.spi.resource; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import org.jboss.resteasy.annotations.Separator; | ||
|
||
@Path("/separator/parameter/{ids}") | ||
public class SeparatorAnnotationAsParameterTargetEndPoint { | ||
@GET | ||
@Produces("text/plain") | ||
public String getSentence(@PathParam("ids") @Separator(",") List<String> ids) { | ||
return "This is your sentence:" + String.join("", ids); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...src/test/java/org/jboss/resteasy/test/core/spi/resource/SeparatorAnnotationBeanParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2023 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* 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.jboss.resteasy.test.core.spi.resource; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.PathParam; | ||
|
||
import org.jboss.resteasy.annotations.Separator; | ||
|
||
public class SeparatorAnnotationBeanParam { | ||
private List<String> ids; | ||
|
||
public List<String> getIds() { | ||
return ids; | ||
} | ||
|
||
@PathParam("ids") | ||
@Separator(",") | ||
public void setIds(List<String> ids) { | ||
this.ids = ids; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "This is your sentence:" + String.join("", ids); | ||
} | ||
} |