-
Notifications
You must be signed in to change notification settings - Fork 72
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 #376 from jim-krueger/358-Add-Filter-Priority-Test
Add priority TCK tests for ContainerRequest/ResponseFilters
- Loading branch information
Showing
10 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
tck/src/main/java/org/eclipse/microprofile/rest/client/tck/FilterPriorityTest.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,92 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.net.URI; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.eclipse.microprofile.rest.client.tck.interfaces.BaseClient; | ||
import org.eclipse.microprofile.rest.client.tck.providers.PriorityResult; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilterPriority1; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilterPriority2; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilterPriority3; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientRequestFilterPriority4; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientResponseFilterPriority1; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientResponseFilterPriority2; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientResponseFilterPriority3; | ||
import org.eclipse.microprofile.rest.client.tck.providers.TestClientResponseFilterPriority4; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.testng.annotations.Test; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
|
||
public class FilterPriorityTest extends Arquillian { | ||
@Deployment | ||
public static Archive<?> createDeployment() { | ||
return ShrinkWrap.create(WebArchive.class, FilterPriorityTest.class.getSimpleName() + ".war") | ||
.addPackage(TestClientRequestFilterPriority1.class.getPackage()) | ||
.addClasses(BaseClient.class); | ||
} | ||
|
||
@Test | ||
public void testPriorities() throws Exception { | ||
TestClientRequestFilterPriority1 filter1 = new TestClientRequestFilterPriority1(); | ||
TestClientRequestFilterPriority2 filter2 = new TestClientRequestFilterPriority2(); | ||
TestClientRequestFilterPriority3 filter3 = new TestClientRequestFilterPriority3(); | ||
TestClientRequestFilterPriority4 filter4 = new TestClientRequestFilterPriority4(); | ||
TestClientResponseFilterPriority1 filter5 = new TestClientResponseFilterPriority1(); | ||
TestClientResponseFilterPriority2 filter6 = new TestClientResponseFilterPriority2(); | ||
TestClientResponseFilterPriority3 filter7 = new TestClientResponseFilterPriority3(); | ||
TestClientResponseFilterPriority4 filter8 = new TestClientResponseFilterPriority4(); | ||
|
||
RestClientBuilder builder = RestClientBuilder.newBuilder() | ||
.register(filter1, 3000) | ||
.register(filter2, 1000) | ||
.register(filter3, 4000) | ||
.register(filter4, 2000) | ||
.register(filter5, 2000) | ||
.register(filter6, 4000) | ||
.register(filter7, 1000) | ||
.register(filter8, 3000); | ||
BaseClient client = builder.baseUri(new URI("http://localhost/stub")).build(BaseClient.class); | ||
|
||
Response response = client.executeBasePost(); | ||
assertEquals(response.getStatus(), 200, | ||
"An exception occurred in the ClientRequestFilter"); | ||
PriorityResult result = PriorityResult.getResult(); | ||
// 4 filters specified in MP Config | ||
assertEquals(4, result.requestsInvoked.size()); | ||
|
||
// priority order specified in same place as filters themselves | ||
assertEquals("TestClientRequestFilterPriority2", result.requestsInvoked.get(0).getSimpleName()); | ||
assertEquals("TestClientRequestFilterPriority4", result.requestsInvoked.get(1).getSimpleName()); | ||
assertEquals("TestClientRequestFilterPriority1", result.requestsInvoked.get(2).getSimpleName()); | ||
assertEquals("TestClientRequestFilterPriority3", result.requestsInvoked.get(3).getSimpleName()); | ||
assertEquals("TestClientResponseFilterPriority2", result.responsesInvoked.get(0).getSimpleName()); | ||
assertEquals("TestClientResponseFilterPriority4", result.responsesInvoked.get(1).getSimpleName()); | ||
assertEquals("TestClientResponseFilterPriority1", result.responsesInvoked.get(2).getSimpleName()); | ||
assertEquals("TestClientResponseFilterPriority3", result.responsesInvoked.get(3).getSimpleName()); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
tck/src/main/java/org/eclipse/microprofile/rest/client/tck/providers/PriorityResult.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 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PriorityResult { | ||
private static PriorityResult INSTANCE; | ||
|
||
public synchronized static PriorityResult getResult() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new PriorityResult(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public synchronized static void clear() { | ||
INSTANCE = null; | ||
} | ||
|
||
public final List<Class<?>> requestsInvoked = new ArrayList<>(); | ||
public final List<Class<?>> responsesInvoked = new ArrayList<>(); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.../org/eclipse/microprofile/rest/client/tck/providers/TestClientRequestFilterPriority1.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,31 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
|
||
public class TestClientRequestFilterPriority1 implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext crc) throws IOException { | ||
PriorityResult.getResult().requestsInvoked.add(this.getClass()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../org/eclipse/microprofile/rest/client/tck/providers/TestClientRequestFilterPriority2.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,31 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
|
||
public class TestClientRequestFilterPriority2 implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext crc) throws IOException { | ||
PriorityResult.getResult().requestsInvoked.add(this.getClass()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../org/eclipse/microprofile/rest/client/tck/providers/TestClientRequestFilterPriority3.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 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
public class TestClientRequestFilterPriority3 implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext crc) throws IOException { | ||
PriorityResult.getResult().requestsInvoked.add(this.getClass()); | ||
crc.abortWith(Response.ok().build()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../org/eclipse/microprofile/rest/client/tck/providers/TestClientRequestFilterPriority4.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,31 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
|
||
public class TestClientRequestFilterPriority4 implements ClientRequestFilter { | ||
@Override | ||
public void filter(ClientRequestContext crc) throws IOException { | ||
PriorityResult.getResult().requestsInvoked.add(this.getClass()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...org/eclipse/microprofile/rest/client/tck/providers/TestClientResponseFilterPriority1.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 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientResponseContext; | ||
import jakarta.ws.rs.client.ClientResponseFilter; | ||
|
||
public class TestClientResponseFilterPriority1 implements ClientResponseFilter { | ||
@Override | ||
public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) | ||
throws IOException { | ||
PriorityResult.getResult().responsesInvoked.add(this.getClass()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...org/eclipse/microprofile/rest/client/tck/providers/TestClientResponseFilterPriority2.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 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientResponseContext; | ||
import jakarta.ws.rs.client.ClientResponseFilter; | ||
|
||
public class TestClientResponseFilterPriority2 implements ClientResponseFilter { | ||
@Override | ||
public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) | ||
throws IOException { | ||
PriorityResult.getResult().responsesInvoked.add(this.getClass()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...org/eclipse/microprofile/rest/client/tck/providers/TestClientResponseFilterPriority3.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 @@ | ||
/* | ||
* Copyright 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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.eclipse.microprofile.rest.client.tck.providers; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientResponseContext; | ||
import jakarta.ws.rs.client.ClientResponseFilter; | ||
|
||
public class TestClientResponseFilterPriority3 implements ClientResponseFilter { | ||
@Override | ||
public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) | ||
throws IOException { | ||
PriorityResult.getResult().responsesInvoked.add(this.getClass()); | ||
} | ||
} |
Oops, something went wrong.