Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zan/feat/local tests #14

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -61,7 +63,7 @@
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</dependency>

<!-- Testing -->
Expand All @@ -83,6 +85,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.zskamljic.restahead</groupId>
<artifactId>test-utils</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down Expand Up @@ -114,7 +122,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.6.3</version>
<version>3.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.exceptions.RequestFailedException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(LocalServerExtension.class)
class AuthorizationServiceTest {
private static final String TOKEN = "token";
private static final String USERNAME = "user";
private static final String PASSWORD = "password";
@LocalUrl
private String localUrl;

private AuthorizationService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(AuthorizationService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(LocalServerExtension.class)
class BodyResponsesServiceTest {
@LocalUrl
private String localUrl;
private BodyResponsesService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(BodyResponsesService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(LocalServerExtension.class)
class BodyServiceTest {
@LocalUrl
private String localUrl;
private BodyService service;

private static final Map<String, Object> DEMO_BODY = Map.of(
Expand All @@ -22,7 +28,7 @@ class BodyServiceTest {

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(BodyService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.demo.adapters.SupplierAdapter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(LocalServerExtension.class)
class CustomAdapterServiceTest {
@LocalUrl
private String url;
private CustomAdapterService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(url)
.converter(new JacksonConverter())
.addAdapter(new SupplierAdapter())
.build(CustomAdapterService.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.client.requests.parts.FilePart;
import io.github.zskamljic.restahead.demo.models.ExternalFormBody;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -15,14 +18,17 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(LocalServerExtension.class)
class FormServiceTest {
@LocalUrl
private String localUrl;
private static final String CONTENT_TYPE = "Content-Type";

private FormService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(FormService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.concurrent.ExecutionException;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(LocalServerExtension.class)
class FutureServiceTest {
@LocalUrl
private String localUrl;
private FutureService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(FutureService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
package io.github.zskamljic.restahead.demo.clients;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.demo.models.HttpBinResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(LocalServerExtension.class)
class HttpBinMethodsServiceTest {
private static final String QUERY_NAME = "q";
private static final String QUERY = "query";
private static final String HEADER_NAME = "Test-Header";
private static final String HEADER = "Header";

@LocalUrl
private String localUrl;
private HttpBinMethodsService service;

@BeforeEach
void setUp() {
service = RestAhead.builder("https://httpbin.org/")
service = RestAhead.builder(localUrl)
.converter(new JacksonConverter())
.build(HttpBinMethodsService.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package io.github.zskamljic.restahead.demo.interceptors;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.client.JavaHttpClient;
import io.github.zskamljic.restahead.demo.clients.InterceptedService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(LocalServerExtension.class)
class PostRequestInterceptorTest {
@LocalUrl
private String localUrl;

@Test
void adaptersExecutedCorrectly() {
var client = new JavaHttpClient();
var postRequestInterceptor = new PostRequestInterceptor();
client.addInterceptor(postRequestInterceptor);
client.addInterceptor(new PreRequestInterceptor());

var service = RestAhead.builder("https://httpbin.org/")
var service = RestAhead.builder(localUrl)
.client(client)
.converter(new JacksonConverter())
.build(InterceptedService.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package io.github.zskamljic.restahead.demo.interceptors;

import io.github.zskamljic.LocalServerExtension;
import io.github.zskamljic.LocalUrl;
import io.github.zskamljic.restahead.JacksonConverter;
import io.github.zskamljic.restahead.RestAhead;
import io.github.zskamljic.restahead.client.JavaHttpClient;
import io.github.zskamljic.restahead.demo.clients.InterceptedService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(LocalServerExtension.class)
class PreRequestInterceptorTest {
@LocalUrl
private String localUrl;

@Test
void interceptorIsCalled() {
var client = new JavaHttpClient();
client.addInterceptor(new PreRequestInterceptor());

var service = RestAhead.builder("https://httpbin.org/")
var service = RestAhead.builder(localUrl)
.client(client)
.converter(new JacksonConverter())
.build(InterceptedService.class);
Expand Down
17 changes: 9 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
<module>rest-ahead-spring</module>
<module>rest-ahead-spring-dialect</module>
<module>rest-ahead-jax-rs</module>
<module>test-utils</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<junit.version>5.8.2</junit.version>
<mockito.version>4.5.1</mockito.version>
<compiler.plugin.version>3.9.0</compiler.plugin.version>
<surefire.version>2.22.2</surefire.version>
<jacoco.version>0.8.8</jacoco.version>
<junit.version>5.9.2</junit.version>
<mockito.version>5.2.0</mockito.version>
<compiler.plugin.version>3.11.0</compiler.plugin.version>
<surefire.version>3.0.0</surefire.version>
<jacoco.version>0.8.10</jacoco.version>

<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
Expand All @@ -47,7 +48,7 @@
<truth.version>1.1.3</truth.version>
<testing.compile.version>0.19</testing.compile.version>

<spring.version>5.3.19</spring.version>
<spring.version>6.0.9</spring.version>
</properties>

<url>https://github.com/zskamljic/rest-ahead</url>
Expand Down Expand Up @@ -98,7 +99,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down Expand Up @@ -129,7 +130,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
6 changes: 6 additions & 0 deletions rest-ahead-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.zskamljic.restahead</groupId>
<artifactId>test-utils</artifactId>
<version>0.5.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading