Skip to content

Commit

Permalink
test(pub-period-migration) add tests for GetInstanceStorageInstanceRe…
Browse files Browse the repository at this point in the history
…sponse
  • Loading branch information
SvitlanaKovalova1 committed Oct 23, 2024
1 parent c4895bb commit a7831b4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
2 changes: 0 additions & 2 deletions ramls/instance-storage-batch.raml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ types:
body:
application/json:
type: instancesWithoutPubPeriod
example:
value: !include examples/instances_get.json
responses:
201:
description: "At least one Instance from the list was created"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ private GetInstanceStorageInstanceResponse(Response response, Object entity) {
super(response, entity);
}

private GetInstanceStorageInstanceResponse(Response response) {
super(response);
}

public static GetInstanceStorageInstanceResponse respond200WithApplicationJson(
Instances entity) {
Response.ResponseBuilder responseBuilder = Response.status(HttpStatus.HTTP_OK.toInt())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.folio.rest.support;

import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static org.folio.HttpStatus.HTTP_BAD_REQUEST;
import static org.folio.HttpStatus.HTTP_INTERNAL_SERVER_ERROR;
import static org.folio.HttpStatus.HTTP_OK;
import static org.folio.HttpStatus.HTTP_UNAUTHORIZED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.folio.rest.jaxrs.model.Instances;
import org.junit.Test;

public class GetInstanceStorageInstanceResponseTest {

@Test
public void shouldRespond200WithApplicationJson() {
var instances = new Instances();

var response = GetInstanceStorageInstanceResponse.respond200WithApplicationJson(instances);

assertNotNull(response);
assertEquals(HTTP_OK.toInt(), response.getStatus());
assertEquals(APPLICATION_JSON, response.getHeaders().getFirst(CONTENT_TYPE));
assertEquals(instances, response.getEntity());
}

@Test
public void shouldRespond400WithTextPlain() {
var errorMessage = "Bad Request";

var response = GetInstanceStorageInstanceResponse.respond400WithTextPlain(errorMessage);

assertNotNull(response);
assertEquals(HTTP_BAD_REQUEST.toInt(), response.getStatus());
assertEquals(TEXT_PLAIN, response.getHeaders().getFirst(CONTENT_TYPE));
assertEquals(errorMessage, response.getEntity());
}

@Test
public void shouldRespond401WithTextPlain() {
var errorMessage = "Unauthorized";

var response = GetInstanceStorageInstanceResponse.respond401WithTextPlain(errorMessage);

assertNotNull(response);
assertEquals(HTTP_UNAUTHORIZED.toInt(), response.getStatus());
assertEquals(TEXT_PLAIN, response.getHeaders().getFirst(CONTENT_TYPE));
assertEquals(errorMessage, response.getEntity());
}

@Test
public void shouldRespond500WithTextPlain() {
var errorMessage = "Internal Server Error";

var response = GetInstanceStorageInstanceResponse.respond500WithTextPlain(errorMessage);

assertNotNull(response);
assertEquals(HTTP_INTERNAL_SERVER_ERROR.toInt(), response.getStatus());
assertEquals(TEXT_PLAIN, response.getHeaders().getFirst(CONTENT_TYPE));
assertEquals(errorMessage, response.getEntity());
}
}

0 comments on commit a7831b4

Please sign in to comment.