Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

SUBMARINE-584. Add unit test for ExperimentRestApi.java #375

Closed
wants to merge 13 commits into from
Closed
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
39 changes: 22 additions & 17 deletions submarine-server/server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down Expand Up @@ -423,22 +423,22 @@
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
Expand All @@ -450,6 +450,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.ws.rs.core.Response;
import java.util.List;

import com.google.common.annotations.VisibleForTesting;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -50,37 +51,45 @@
@Path(RestConstants.V1 + "/" + RestConstants.EXPERIMENT)
@Produces({MediaType.APPLICATION_JSON + "; " + RestConstants.CHARSET_UTF8})
public class ExperimentRestApi {
private final ExperimentManager experimentManager = ExperimentManager.getInstance();
private ExperimentManager experimentManager = ExperimentManager.getInstance();

@VisibleForTesting
public void setExperimentManager(ExperimentManager experimentManager) {
aeioulisa marked this conversation as resolved.
Show resolved Hide resolved
this.experimentManager = experimentManager;
}

/**
* Return the Pong message for test the connectivity
*
* @return Pong message
*/
@GET
@Path(RestConstants.PING)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(summary = "Ping submarine server",
tags = {"experiment"},
description = "Return the Pong message for test the connectivity",
responses = {
@ApiResponse(responseCode = "200", description = "successful operation",
content = @Content(schema = @Schema(implementation = String.class)))})
tags = {"experiment"},
description = "Return the Pong message for test the connectivity",
responses = {
@ApiResponse(responseCode = "200", description = "successful operation",
content = @Content(schema = @Schema(implementation = String.class)))})
public Response ping() {
return new JsonResponse.Builder<String>(Response.Status.OK)
.success(true).result("Pong").build();
}

/**
* Returns the contents of {@link Experiment} that submitted by user.
*
* @param spec spec
* @return the contents of experiment
*/
@POST
@Consumes({RestConstants.MEDIA_TYPE_YAML, MediaType.APPLICATION_JSON})
@Operation(summary = "Create an experiment",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
public Response createExperiment(ExperimentSpec spec) {
try {
Experiment experiment = experimentManager.createExperiment(spec);
Expand All @@ -93,14 +102,15 @@ public Response createExperiment(ExperimentSpec spec) {

/**
* List all experiment for the user
*
* @return experiment list
*/
@GET
@Operation(summary = "List experiments",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
public Response listExperiments(@QueryParam("status") String status) {
try {
List<Experiment> experimentList = experimentManager.listExperimentsByStatus(status);
Expand All @@ -113,17 +123,18 @@ public Response listExperiments(@QueryParam("status") String status) {

/**
* Returns the experiment detailed info by specified experiment id
*
* @param id experiment id
* @return the detailed info of experiment
*/
@GET
@Path("/{id}")
@Operation(summary = "Get the experiment's detailed info by id",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
public Response getExperiment(@PathParam(RestConstants.ID) String id) {
try {
Experiment experiment = experimentManager.getExperiment(id);
Expand All @@ -138,11 +149,11 @@ public Response getExperiment(@PathParam(RestConstants.ID) String id) {
@Path("/{id}")
@Consumes({RestConstants.MEDIA_TYPE_YAML, MediaType.APPLICATION_JSON})
@Operation(summary = "Update the experiment in the submarine server with spec",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
public Response patchExperiment(@PathParam(RestConstants.ID) String id, ExperimentSpec spec) {
try {
Experiment experiment = experimentManager.patchExperiment(id, spec);
Expand All @@ -155,17 +166,18 @@ public Response patchExperiment(@PathParam(RestConstants.ID) String id, Experime

/**
* Returns the experiment that deleted
*
* @param id experiment id
* @return the detailed info about deleted experiment
*/
@DELETE
@Path("/{id}")
@Operation(summary = "Delete the experiment",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
public Response deleteExperiment(@PathParam(RestConstants.ID) String id) {
try {
Experiment experiment = experimentManager.deleteExperiment(id);
Expand All @@ -179,10 +191,10 @@ public Response deleteExperiment(@PathParam(RestConstants.ID) String id) {
@GET
@Path("/logs")
@Operation(summary = "List experiment's log",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class)))})
public Response listLog(@QueryParam("status") String status) {
try {
List<ExperimentLog> experimentLogList = experimentManager.listExperimentLogsByStatus(status);
Expand All @@ -197,11 +209,11 @@ public Response listLog(@QueryParam("status") String status) {
@GET
@Path("/logs/{id}")
@Operation(summary = "Log experiment by id",
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
tags = {"experiment"},
responses = {
@ApiResponse(description = "successful operation", content = @Content(
schema = @Schema(implementation = JsonResponse.class))),
@ApiResponse(responseCode = "404", description = "Experiment not found")})
public Response getLog(@PathParam(RestConstants.ID) String id) {
try {
ExperimentLog experimentLog = experimentManager.getExperimentLog(id);
Expand Down
Loading