List of usage examples for org.springframework.http HttpHeaders AUTHORIZATION
String AUTHORIZATION
To view the source code for org.springframework.http HttpHeaders AUTHORIZATION.
Click Source Link
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getOutputStream_NOK_Unauthorized(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")) .andExpect(content().contentType(owncloudFileResource.getMediaType())) .andExpect(content().bytes(new byte[] { 1 })).andRespond(withStatus(HttpStatus.UNAUTHORIZED)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getOutputStream_OK_CreateNewFile(URI href, MediaType mediaType, String testFileContent) throws Exception { Mockito.when(sardine.list(getResourcePath(href), 0)) .thenThrow(new SardineException("No File", HttpStatus.NOT_FOUND.value(), null)); mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType)) .andExpect(content().string(testFileContent)).andRespond(withSuccess()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getOutputStream_OK_OverwriteFile(URI href, MediaType mediaType, String testFileContent) throws Exception { List<DavResource> davResources = Lists.newArrayList(createDavResourceFrom(OwncloudTestFileResourceImpl .fileBuilder()// w w w.java2 s .c o m .owncloudResource(OwncloudTestResourceImpl.builder().href(href).mediaType(mediaType).build()) .testFileContent(testFileContent).build(), Locale.GERMAN)); Mockito.when(sardine.list(getResourcePath(href))).thenReturn(davResources); mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType)) .andExpect(content().string(testFileContent)).andRespond(withSuccess()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_deleteFile_OK(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.DELETE)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andRespond(withNoContent()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_deleteFile_NOK_FileNotExists(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.DELETE)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andRespond(withStatus(HttpStatus.NOT_FOUND)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_deleteFile_NOK_OtherError(OwncloudTestFileResourceImpl owncloudFileResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudFileResource.getHref())).andExpect(method(HttpMethod.DELETE)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andRespond(withStatus(HttpStatus.UNAUTHORIZED)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_deleteDirectory_OK(OwncloudTestResourceImpl owncloudResource) throws Exception { mockServer.expect(requestToWithPrefix(owncloudResource.getHref())).andExpect(method(HttpMethod.DELETE)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andRespond(withNoContent()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getOutputStram_NOK_FileTooBig(URI href, MediaType mediaType, String testFileContent) throws Exception { Mockito.when(sardine.list(getResourcePath(href), 0)) .thenThrow(new SardineException("No File", HttpStatus.NOT_FOUND.value(), null)); mockServer.expect(requestToWithPrefix(href)).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType)) .andExpect(content().string(testFileContent)) .andRespond(withStatus(HttpStatus.INSUFFICIENT_STORAGE)); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
@Override protected void prepare_getQuota_OneFile(URI uri, MediaType mediaType, String testFileContent, OwncloudQuota expectedFirst, OwncloudQuota expectedSecond) throws Exception { mockServer.expect(requestToWithPrefix(uri)).andExpect(method(HttpMethod.PUT)) .andExpect(header(HttpHeaders.AUTHORIZATION, getBasicAuthorizationHeader())) .andExpect(header(HttpHeaders.CONNECTION, "keep-alive")).andExpect(content().contentType(mediaType)) .andExpect(content().string(testFileContent)).andRespond(withSuccess()); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Mockito.when(userQueryService.getQuota(authentication.getName())).then(new Answer<OwncloudQuota>() { private int count = 0; @Override/* w w w .j a va 2 s .c om*/ public OwncloudQuota answer(InvocationOnMock invocation) throws Throwable { if (count++ == 0) { return OwncloudRestQuotaImpl.builder().username(expectedFirst.getUsername()) .free(expectedFirst.getFree()).relative(expectedFirst.getRelative()) .total(expectedFirst.getTotal()).used(expectedFirst.getUsed()).build(); } return OwncloudRestQuotaImpl.builder().username(expectedSecond.getUsername()) .free(expectedSecond.getFree()).relative(expectedSecond.getRelative()) .total(expectedSecond.getTotal()).used(expectedSecond.getUsed()).build(); } }); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUtils.java
public static void addAuthorizationHeader(HttpHeaders headers, Authentication authentication) { headers.add(HttpHeaders.AUTHORIZATION, encodeCredentialsForBasicAuthorization(authentication)); }