-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to jvm-test-suite Gradle plugin.
- Loading branch information
Showing
12 changed files
with
256 additions
and
28 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
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
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
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
75 changes: 75 additions & 0 deletions
75
.../java/simplyrestful/api/framework/client/integrationtest/implementation/TestResource.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,75 @@ | ||
package simplyrestful.api.framework.client.integrationtest.implementation; | ||
|
||
import java.net.URI; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.UriBuilder; | ||
import simplyrestful.api.framework.resources.APIResource; | ||
import simplyrestful.api.framework.resources.Link; | ||
|
||
public class TestResource extends APIResource { | ||
public static final String MEDIA_TYPE_JSON = "application/x.testresource-v1+json"; | ||
public static final UUID TEST_RESOURCE_ID = UUID.randomUUID(); | ||
public static final String ADDITIONAL_FIELD_TEST_VALUE = "additional-field-value"; | ||
|
||
private String additionalField; | ||
|
||
public static URI getResourceUri(UUID id) { | ||
return UriBuilder.fromUri(TestWebResource.getBaseUri()).path(TestWebResource.class).path(id.toString()).build(); | ||
} | ||
|
||
private TestResource(URI resourceUri, String additionalField) { | ||
this.additionalField = additionalField; | ||
this.setSelf(new Link(resourceUri, customJsonMediaType())); | ||
} | ||
|
||
public TestResource() { | ||
} | ||
|
||
public static TestResource testInstance() { | ||
return new TestResource(TestResource.getResourceUri(TEST_RESOURCE_ID), ADDITIONAL_FIELD_TEST_VALUE); | ||
} | ||
|
||
public static TestResource random() { | ||
return TestResource.withId(UUID.randomUUID()); | ||
} | ||
|
||
public static TestResource withId(UUID resourceId) { | ||
return new TestResource(getResourceUri(resourceId), ADDITIONAL_FIELD_TEST_VALUE); | ||
} | ||
|
||
@Override | ||
public MediaType customJsonMediaType() { | ||
return MediaType.valueOf(MEDIA_TYPE_JSON); | ||
} | ||
|
||
public String getAdditionalField() { | ||
return additionalField; | ||
} | ||
|
||
public void setAdditionalField(String additionalField) { | ||
this.additionalField = additionalField; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = super.hashCode(); | ||
result = prime * result + Objects.hash(additionalField); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (!super.equals(obj)) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
TestResource other = (TestResource) obj; | ||
return Objects.equals(additionalField, other.additionalField); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...va/simplyrestful/api/framework/client/integrationtest/implementation/TestWebResource.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,90 @@ | ||
package simplyrestful.api.framework.client.integrationtest.implementation; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.InternalServerErrorException; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import simplyrestful.api.framework.DefaultWebResource; | ||
import simplyrestful.api.framework.queryparams.SortOrder; | ||
import simplyrestful.api.framework.webresource.api.implementation.DefaultCollectionGetEventStream; | ||
|
||
@Path(TestWebResource.WEBRESOURCE_PATH) | ||
@OpenAPIDefinition(tags = { @Tag(name = "Test Resources") }) | ||
@Produces(TestResource.MEDIA_TYPE_JSON) | ||
@Consumes(TestResource.MEDIA_TYPE_JSON) | ||
public class TestWebResource implements DefaultWebResource<TestResource>, DefaultCollectionGetEventStream<TestResource> { | ||
public static final String WEBRESOURCE_PATH = "testresources"; | ||
public static final UUID ERROR_READ_RESOURCE_ID = UUID.randomUUID(); | ||
public static final UUID ERROR_UPDATE_RESOURCE_ID = UUID.randomUUID(); | ||
private static URI baseUri; | ||
|
||
public static URI getBaseUri() { | ||
return baseUri; | ||
} | ||
|
||
public static void setBaseUri(URI baseUri) { | ||
TestWebResource.baseUri = baseUri; | ||
} | ||
|
||
@Override | ||
public TestResource create(TestResource resource, UUID resourceUUID) { | ||
// The provided resource is not actually stored anywhere in this test API. | ||
return resource; | ||
} | ||
|
||
@Override | ||
public TestResource read(UUID resourceUUID) { | ||
if (Objects.equals(resourceUUID, TestResource.TEST_RESOURCE_ID)) { | ||
return TestResource.testInstance(); | ||
} | ||
if (Objects.equals(resourceUUID, ERROR_READ_RESOURCE_ID)) { | ||
throw new InternalServerErrorException("Pretending that something went wrong on the server"); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public TestResource update(TestResource resource, UUID resourceUUID) { | ||
if (Objects.equals(resourceUUID, ERROR_UPDATE_RESOURCE_ID)) { | ||
throw new InternalServerErrorException("Pretending that something went wrong on the server"); | ||
} | ||
return TestResource.testInstance(); | ||
} | ||
|
||
@Override | ||
public TestResource delete(UUID resourceUUID) { | ||
if (Objects.equals(resourceUUID, TestResource.TEST_RESOURCE_ID)) { | ||
return TestResource.testInstance(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<TestResource> list(int pageStart, int pageSize, List<String> fields, String query, List<SortOrder> sort) { | ||
return Arrays.asList(TestResource.testInstance(), TestResource.random()); | ||
} | ||
|
||
@Override | ||
public int count(String query) { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public Stream<TestResource> stream(List<String> fields, String query, List<SortOrder> sort) { | ||
return Stream.of(TestResource.testInstance(), TestResource.random()); | ||
} | ||
|
||
@Override | ||
public boolean exists(UUID resourceUUID) { | ||
return this.read(resourceUUID) != null; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...src/test/java/simplyrestful/api/framework/client/test/SimplyRESTfulClientFactoryTest.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,28 @@ | ||
package simplyrestful.api.framework.client.test; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; | ||
|
||
import jakarta.ws.rs.client.Client; | ||
import simplyrestful.api.framework.client.SimplyRESTfulClientFactory; | ||
import simplyrestful.api.framework.client.test.implementation.TestResource; | ||
import simplyrestful.api.framework.providers.ObjectMapperProvider; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class SimplyRESTfulClientFactoryTest { | ||
@Mock | ||
Client client; | ||
|
||
@Test | ||
public void clientFactory_shouldUseProvidedJaxrsClientInClientAndRegisterRequiredProviders() { | ||
new SimplyRESTfulClientFactory<TestResource>(client).newClient(null, TestResource.class); | ||
Mockito.verify(client).register(JacksonJsonProvider.class); | ||
Mockito.verify(client).register(ObjectMapperProvider.class); | ||
} | ||
|
||
} |
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
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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