Java Code Examples for play.mvc.Http#Response
The following examples show how to use
play.mvc.Http#Response .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolutionSettingsControllerTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = SolutionSettingsControllerTest.TIMEOUT) @Category({UnitTest.class}) public void getLogoShouldReturnExpectedNameAndType() throws BaseException, ExecutionException, InterruptedException { // Arrange String image = rand.NextString(); String type = rand.NextString(); String name = rand.NextString(); Logo model = new Logo(image, type, name, false); getLogoMockSetup(model); controller = new SolutionSettingsController(mockStorage, mockActions); Http.Response mockResponse = TestUtils.setRequest(SolutionSettingsControllerTest.LOGO_BODY); // Act Result result = controller.getLogoAsync().toCompletableFuture().get(); byte[] bytes = TestUtils.getBytes(result); byte[] bytesold = Base64.getDecoder().decode(model.getImage().getBytes()); // Assert assertEquals(ByteString.fromArray(bytes), ByteString.fromArray(bytesold)); Mockito.verify(mockResponse).setHeader(Logo.NAME_HEADER, name); Mockito.verify(mockResponse).setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(false)); }
Example 2
Source File: SolutionSettingsControllerTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = SolutionSettingsControllerTest.TIMEOUT) @Category({UnitTest.class}) public void getLogoShouldReturnDefaultLogo() throws BaseException, ExecutionException, InterruptedException { // Arrange Logo model = Logo.Default; getLogoMockSetup(model); controller = new SolutionSettingsController(mockStorage, mockActions); Http.Response mockResponse = TestUtils.setRequest(SolutionSettingsControllerTest.LOGO_BODY); // Act Result result = controller.getLogoAsync().toCompletableFuture().get(); byte[] bytes = TestUtils.getBytes(result); byte[] bytesold = Base64.getDecoder().decode(model.getImage().getBytes()); // Assert assertEquals(ByteString.fromArray(bytes), ByteString.fromArray(bytesold)); Mockito.verify(mockResponse).setHeader(Logo.NAME_HEADER, Logo.Default.getName()); Mockito.verify(mockResponse).setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(true)); }
Example 3
Source File: SolutionSettingsControllerTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = SolutionSettingsControllerTest.TIMEOUT) @Category({UnitTest.class}) public void setLogoShouldReturnGivenLogoAndName() throws BaseException, ExecutionException, InterruptedException, UnsupportedEncodingException, URISyntaxException { // Arrange String image = rand.NextString(); String type = rand.NextString(); String name = rand.NextString(); Logo model = new Logo(image, type, name, false); setLogoMockSetup(model); controller = new SolutionSettingsController(mockStorage, mockActions); Http.Response mockResponse = TestUtils.setRequest(SolutionSettingsControllerTest.LOGO_BODY); // Act byte[] bytes = TestUtils.getBytes(controller.setLogoAsync().toCompletableFuture().get()); byte[] bytesold = Base64.getDecoder().decode(model.getImage().getBytes()); // Assert assertEquals(ByteString.fromArray(bytes), ByteString.fromArray(bytesold)); Mockito.verify(mockResponse).setHeader(Logo.NAME_HEADER, name); Mockito.verify(mockResponse).setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(false)); }
Example 4
Source File: SolutionSettingsControllerTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = SolutionSettingsControllerTest.TIMEOUT) @Category({UnitTest.class}) public void setLogoShouldReturnGivenLogo() throws BaseException, ExecutionException, InterruptedException, UnsupportedEncodingException, URISyntaxException { // Arrange String image = rand.NextString(); String type = rand.NextString(); Logo model = new Logo(image, type, null, false); setLogoMockSetup(model); controller = new SolutionSettingsController(mockStorage, mockActions); Http.Response mockResponse = TestUtils.setRequest(SolutionSettingsControllerTest.LOGO_BODY); // Act byte[] bytes = TestUtils.getBytes(controller.setLogoAsync().toCompletableFuture().get()); byte[] bytesold = Base64.getDecoder().decode(model.getImage().getBytes()); // Assert assertEquals(ByteString.fromArray(bytes), ByteString.fromArray(bytesold)); Mockito.verify(mockResponse).setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(false)); }
Example 5
Source File: SolutionSettingsControllerTest.java From remote-monitoring-services-java with MIT License | 6 votes |
@Test(timeout = SolutionSettingsControllerTest.TIMEOUT) @Category({UnitTest.class}) public void setLogoShouldReturnGivenName() throws BaseException, ExecutionException, InterruptedException, UnsupportedEncodingException, URISyntaxException { // Arrange String name = rand.NextString(); Logo model = new Logo(null, null, name, false); setLogoMockSetup(model); controller = new SolutionSettingsController(mockStorage, mockActions); Http.Response mockResponse = TestUtils.setRequest(SolutionSettingsControllerTest.LOGO_BODY); // Act byte[] bytes = TestUtils.getBytes(controller.setLogoAsync().toCompletableFuture().get()); byte[] emptyBytes = new byte[0]; // Assert assertEquals(ByteString.fromArray(bytes), ByteString.fromArray(emptyBytes)); Mockito.verify(mockResponse).setHeader(Logo.NAME_HEADER, name); Mockito.verify(mockResponse).setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(false)); }
Example 6
Source File: TestUtils.java From remote-monitoring-services-java with MIT License | 5 votes |
public static void setRequest(String body) { Http.Request mockRequest = mock(Http.Request.class); when(mockRequest.body()).thenReturn(new Http.RequestBody(Json.parse(body))); Http.Response mockResponse = mock(Http.Response.class); doNothing().when(mockResponse).setHeader( any(String.class), any(String.class)); Http.Context mockContext = mock(Http.Context.class); when(mockContext.request()).thenReturn(mockRequest); when(mockContext.response()).thenReturn(mockResponse); Http.Context.current.set(mockContext); }
Example 7
Source File: TestUtils.java From remote-monitoring-services-java with MIT License | 5 votes |
public static Http.Response setRequest(String body) { Http.Request mockRequest = mock(Http.Request.class); when(mockRequest.body()).thenReturn(new Http.RequestBody(Json.parse(body))); Http.Response mockResponse = mock(Http.Response.class); doNothing().when(mockResponse).setHeader( any(String.class), any(String.class)); Http.Context mockContext = mock(Http.Context.class); when(mockContext.request()).thenReturn(mockRequest); when(mockContext.response()).thenReturn(mockResponse); Http.Context.current.set(mockContext); return mockResponse; }
Example 8
Source File: SolutionSettingsController.java From remote-monitoring-services-java with MIT License | 5 votes |
@Authorize("ReadAll") public CompletionStage<Result> getLogoAsync() throws BaseException { Http.Response response = response(); return storage.getLogoAsync() .thenApply(result -> { return setImageResponse(result, response); }); }
Example 9
Source File: SolutionSettingsController.java From remote-monitoring-services-java with MIT License | 5 votes |
@Authorize("ReadAll") public CompletionStage<Result> setLogoAsync() throws BaseException { Http.RequestBody body = request().body(); ByteString byteString = body.asBytes(); byte[] bytes; // If byteString is null, need to read bytes from file if (byteString == null) { bytes = this.convertToByteArray(body.asRaw()); } else { bytes = byteString.toByteBuffer().array(); } Logo model = new Logo(); if (bytes.length > 0) { model.setType(request().contentType().orElse("application/octet-stream")); model.setImage(Base64.getEncoder().encodeToString(bytes)); } Optional<String> logoName = request().header(Logo.NAME_HEADER); if (logoName.isPresent()) { model.setName(logoName.get()); } //for some unknown issue on travis test, make a variable to refer the response in current thread context. Http.Response response = response(); return storage.setLogoAsync(model) .thenApply(result -> { return setImageResponse(result, response); }); }
Example 10
Source File: SolutionSettingsController.java From remote-monitoring-services-java with MIT License | 5 votes |
private Result setImageResponse(Logo model, Http.Response response) { if (model.getName() != null) { response.setHeader(Logo.NAME_HEADER, model.getName()); } response.setHeader(Logo.IS_DEFAULT_HEADER, Boolean.toString(model.getDefault())); response.setHeader(SolutionSettingsController.ACCESS_CONTROL_EXPOSE_HEADERS, Logo.NAME_HEADER + "," + Logo.IS_DEFAULT_HEADER); if (model.getImage() == null) { return ok(); } return ok(Base64.getDecoder().decode(model.getImage().getBytes())).as(model.getType()); }
Example 11
Source File: TestUtils.java From remote-monitoring-services-java with MIT License | 5 votes |
public static Http.Response setRequest(String body) { Http.Request mockRequest = mock(Http.Request.class); when(mockRequest.body()).thenReturn(new Http.RequestBody(Json.parse(body))); Http.Response mockResponse = mock(Http.Response.class); doNothing().when(mockResponse).setHeader( any(String.class), any(String.class)); Http.Context mockContext = mock(Http.Context.class); when(mockContext.request()).thenReturn(mockRequest); when(mockContext.response()).thenReturn(mockResponse); Http.Context.current.set(mockContext); return mockResponse; }
Example 12
Source File: PluginCollection.java From restcommander with Apache License 2.0 | 5 votes |
public boolean serveStatic(VirtualFile file, Http.Request request, Http.Response response){ for (PlayPlugin plugin : getEnabledPlugins()) { if (plugin.serveStatic(file, request, response)) { //raw = true; return true; } } return false; }
Example 13
Source File: PluginCollection.java From restcommander with Apache License 2.0 | 5 votes |
public boolean rawInvocation(Http.Request request, Http.Response response)throws Exception{ for (PlayPlugin plugin : getEnabledPlugins()) { if (plugin.rawInvocation(request, response)) { //raw = true; return true; } } return false; }
Example 14
Source File: Utils.java From NationStatesPlusPlus with MIT License | 4 votes |
public static Result validateRequest(Http.Request request, Http.Response response, NationStates api, DatabaseAccess access) { return validateRequest(request, response, api, access, true); }
Example 15
Source File: Result.java From restcommander with Apache License 2.0 | 4 votes |
protected void setContentTypeIfNotSet(Http.Response response, String contentType) { response.setContentTypeIfNotSet(contentType); }
Example 16
Source File: TestUtils.java From remote-monitoring-services-java with MIT License | 4 votes |
public static Http.Response setRequest(Object obj) { final String toJson = Json.toJson(obj).toString(); return setRequest(toJson); }
Example 17
Source File: Result.java From restcommander with Apache License 2.0 | votes |
public abstract void apply(Http.Request request, Http.Response response);