-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Integration test for Jaxrs(#152)
add Integration test for Jaxrs.
- Loading branch information
Showing
69 changed files
with
1,753 additions
and
60 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2022 OPPO ESA Stack Project | ||
~ 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. | ||
--> | ||
|
||
<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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>restlight-integration-test</artifactId> | ||
<groupId>io.esastack</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jaxrs-test</artifactId> | ||
|
||
<name>Restlight :: Integration Test :: Jaxrs test</name> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.esastack</groupId> | ||
<artifactId>restlight-starter</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>io.esastack</groupId> | ||
<artifactId>restlight-springmvc-annotation</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>io.esastack</groupId> | ||
<artifactId>restlight-springmvc-provider</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.esastack</groupId> | ||
<artifactId>restclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.esastack</groupId> | ||
<artifactId>restlight-jaxrs-provider</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
27 changes: 27 additions & 0 deletions
27
...s-test/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Filter.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,27 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.annotation; | ||
|
||
import jakarta.ws.rs.NameBinding; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@NameBinding | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(value = RetentionPolicy.RUNTIME) | ||
public @interface Filter { | ||
} |
27 changes: 27 additions & 0 deletions
27
...t/src/main/java/io/esastack/restlight/integration/jaxrs/cases/annotation/Interceptor.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,27 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.annotation; | ||
|
||
import jakarta.ws.rs.NameBinding; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@NameBinding | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(value = RetentionPolicy.RUNTIME) | ||
public @interface Interceptor { | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/java/io/esastack/restlight/integration/jaxrs/cases/applications/ApplicationImpl.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,34 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.applications; | ||
|
||
import io.esastack.restlight.integration.jaxrs.cases.resources.ManualInjectResource; | ||
import jakarta.ws.rs.ApplicationPath; | ||
import jakarta.ws.rs.core.Application; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@ApplicationPath("/integration/test") | ||
@Component | ||
public class ApplicationImpl extends Application { | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
Set<Class<?>> classes = new HashSet<>(); | ||
classes.add(ManualInjectResource.class); | ||
return classes; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...est/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyReader.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,43 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.ext.MessageBodyReader; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.InputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
@Provider | ||
@Component | ||
public class BodyReader implements MessageBodyReader<MessageBodyData> { | ||
|
||
@Override | ||
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public MessageBodyData readFrom(Class<MessageBodyData> type, Type genericType, Annotation[] annotations, | ||
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, | ||
InputStream entityStream) throws WebApplicationException { | ||
return MessageBodyData.Builder.aBodyMessageData().name("test").build(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...est/src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/BodyWriter.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,49 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import io.esastack.restlight.core.serialize.JacksonSerializer; | ||
import io.esastack.restlight.integration.jaxrs.entity.MessageBodyData; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.ext.MessageBodyWriter; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
@Provider | ||
@Component | ||
public class BodyWriter implements MessageBodyWriter<MessageBodyData> { | ||
|
||
@Override | ||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void writeTo(MessageBodyData messageBodyData, Class<?> type, Type genericType, Annotation[] annotations, | ||
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, | ||
OutputStream entityStream) throws WebApplicationException, IOException { | ||
if (messageBodyData.getName() == null) { | ||
messageBodyData.setName("test-byBodyWriter"); | ||
} | ||
httpHeaders.add("Content-Type", mediaType.getType() + "/" + mediaType.getSubtype()); | ||
entityStream.write(new JacksonSerializer().serialize(messageBodyData)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/io/esastack/restlight/integration/jaxrs/cases/providers/DynamicFeature.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,27 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import jakarta.ws.rs.container.ResourceInfo; | ||
import jakarta.ws.rs.core.FeatureContext; | ||
|
||
public class DynamicFeature implements jakarta.ws.rs.container.DynamicFeature { | ||
|
||
@Override | ||
public void configure(ResourceInfo resourceInfo, FeatureContext context) { | ||
if (resourceInfo.getResourceMethod().getName().equals("dynamicFeature")) { | ||
context.property("name", "test"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...n/java/io/esastack/restlight/integration/jaxrs/cases/providers/GlobalExceptionMapper.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,32 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import io.esastack.restlight.integration.jaxrs.entity.UserData; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Provider | ||
@Component | ||
public class GlobalExceptionMapper implements ExceptionMapper<IllegalArgumentException> { | ||
|
||
@Override | ||
public Response toResponse(IllegalArgumentException exception) { | ||
return Response.status(200) | ||
.entity(UserData.Builder.anUserData().name(exception.getMessage()).build()) | ||
.build(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ava/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingRequestFilter.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 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import io.esastack.restlight.integration.jaxrs.cases.annotation.Filter; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.container.ContainerRequestFilter; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Filter | ||
@Provider | ||
@Component | ||
public class NameBindingRequestFilter implements ContainerRequestFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext) { | ||
requestContext.getHeaders().add("name", "test"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...va/io/esastack/restlight/integration/jaxrs/cases/providers/NameBindingResponseFilter.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,34 @@ | ||
/* | ||
* Copyright 2022 OPPO ESA Stack Project | ||
* 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 io.esastack.restlight.integration.jaxrs.cases.providers; | ||
|
||
import io.esastack.restlight.integration.jaxrs.cases.annotation.Filter; | ||
import io.esastack.restlight.integration.jaxrs.entity.UserData; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.container.ContainerResponseContext; | ||
import jakarta.ws.rs.container.ContainerResponseFilter; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Filter | ||
@Provider | ||
@Component | ||
public class NameBindingResponseFilter implements ContainerResponseFilter { | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { | ||
UserData userData = (UserData) responseContext.getEntity(); | ||
userData.setName("test"); | ||
} | ||
} |
Oops, something went wrong.