content getting int test
This commit is contained in:
parent
5c54067cdb
commit
e7332d94b3
4 changed files with 35 additions and 17 deletions
|
@ -1,26 +1,40 @@
|
|||
package net.schowek.nextclouddlna.controller
|
||||
|
||||
|
||||
import net.schowek.nextclouddlna.nextcloud.content.ContentTreeProvider
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import support.IntegrationSpecification
|
||||
|
||||
class ContentControllerIntTest extends IntegrationSpecification {
|
||||
@Autowired
|
||||
ContentTreeProvider contentTreeProvider
|
||||
|
||||
def "should serve nextcloud files"() {
|
||||
given:
|
||||
def items = contentTreeProvider.tree.items
|
||||
|
||||
def "should process GET request for content"() {
|
||||
when:
|
||||
ResponseEntity<byte[]> response = restTemplate().getForEntity(urlWithPort("/c/16"), byte[]);
|
||||
Map<Integer, ResponseEntity<byte[]>> results = items.keySet().collectEntries() {
|
||||
[Integer.valueOf(it), restTemplate().getForEntity(urlWithPort("/c/$it"), byte[])]
|
||||
}
|
||||
|
||||
then:
|
||||
response.statusCode == HttpStatus.OK
|
||||
with(response.headers.each { it.key.toLowerCase() }) {
|
||||
assert it['content-type'] == ['image/jpeg']
|
||||
assert it['accept-ranges'] == ["bytes"]
|
||||
assert it.containsKey('contentfeatures.dlna.org')
|
||||
assert it.containsKey('transfermode.dlna.org')
|
||||
assert it.containsKey('realtimeinfo.dlna.org')
|
||||
items.values().each { item ->
|
||||
assert results.containsKey(item.id)
|
||||
with(results.get(item.id)) { response ->
|
||||
response.statusCode == HttpStatus.OK
|
||||
with(response.headers.each { it.key.toLowerCase() }) {
|
||||
assert it['content-type'] == [item.format.mime]
|
||||
assert it['accept-ranges'] == ["bytes"]
|
||||
assert it.containsKey('contentfeatures.dlna.org')
|
||||
assert it.containsKey('transfermode.dlna.org')
|
||||
assert it.containsKey('realtimeinfo.dlna.org')
|
||||
}
|
||||
response.body.length == item.fileLength
|
||||
}
|
||||
}
|
||||
response.body.length == 593508
|
||||
}
|
||||
|
||||
def "should return 404 if content does not exist"() {
|
||||
|
|
|
@ -29,6 +29,10 @@ class IntegrationSpecification extends Specification {
|
|||
@Autowired
|
||||
private ServerInfoProvider serverInfoProvider
|
||||
|
||||
def setup() {
|
||||
System.err.println("SETUP PARENT")
|
||||
}
|
||||
|
||||
protected String urlWithPort(String uri = "") {
|
||||
return "http://localhost:" + serverInfoProvider.port + uri;
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@ INSERT INTO `oc_filecache` VALUES
|
|||
(155,2,'appdata_integration/preview/c/5/1/c/e/4/1/14','bb5cbf8f27a56a12e83245d5532d0381',271,'14',2,1,107111,1696697008,1696697008,0,0,'',31,''),
|
||||
(164,2,'appdata_integration/preview/c/5/1/c/e/4/1/14/500-500-max.png','15b68a8c62dab8e7c3773ce0d1ac4f43',155,'500-500-max.png',11,10,50545,1695737792,1695737792,0,0,'',27,''),
|
||||
|
||||
(803,2,'appdata_integration/preview/c/7/4/d/9/7/b/16','71e9a2780187bcba09819c38341af594',271,'16',2,1,129292,1696698525,1696698525,0,0,'',31,''),
|
||||
(804,2,'appdata_integration/preview/c/7/4/d/9/7/b/16/1000-667-max.jpg','c6df2f52ea6e2bce26b0c0c9cb99b7a5',803,'1000-667-max.jpg',12,10,81421,1696698525,1696698525,0,0,'',27,''),
|
||||
(803,2,'appdata_integration/preview/c/5/1/c/e/4/1/16','71e9a2780187bcba09819c38341af594',271,'16',2,1,129292,1696698525,1696698525,0,0,'',31,''),
|
||||
(804,2,'appdata_integration/preview/c/5/1/c/e/4/1/16/1000-667-max.jpg','c6df2f52ea6e2bce26b0c0c9cb99b7a5',803,'1000-667-max.jpg',12,10,81421,1696698525,1696698525,0,0,'',27,''),
|
||||
|
||||
(811,2,'appdata_integration/preview/7/0/e/f/d/f/2/17','9fbd157aa2c41b17eb7ec32e9f93551f',271,'17',2,1,84401,1696698525,1696698525,0,0,'',31,''),
|
||||
(812,2,'appdata_integration/preview/7/0/e/f/d/f/2/17/1000-667-max.jpg','351f42173986513e412dbcc450bd4b19',811,'1000-667-max.jpg',12,10,53672,1696698525,1696698525,0,0,'',27,'');
|
||||
(811,2,'appdata_integration/preview/c/5/1/c/e/4/1/17','9fbd157aa2c41b17eb7ec32e9f93551f',271,'17',2,1,84401,1696698525,1696698525,0,0,'',31,''),
|
||||
(812,2,'appdata_integration/preview/c/5/1/c/e/4/1/17/1000-667-max.jpg','351f42173986513e412dbcc450bd4b19',811,'1000-667-max.jpg',12,10,53672,1696698525,1696698525,0,0,'',27,'');
|
||||
|
||||
INSERT INTO `oc_group_folders` VALUES
|
||||
(1,'family folder',-3,0);
|
||||
|
|
|
@ -35,11 +35,11 @@ class ContentController(
|
|||
): ResponseEntity<FileSystemResource> {
|
||||
return contentTreeProvider.getItem(id)?.let { item ->
|
||||
if (!request.getHeaders("range").hasMoreElements()) {
|
||||
logger.info("Serving content {} {}", request.method, id)
|
||||
logger.info("Serving content ${request.method} $id")
|
||||
}
|
||||
val fileSystemResource = FileSystemResource(item.path)
|
||||
if (!fileSystemResource.exists()) {
|
||||
logger.info("Could not find file for item id: {}", id)
|
||||
logger.info("Could not find file ${fileSystemResource.path} for item id: $id")
|
||||
ResponseEntity(HttpStatus.NOT_FOUND)
|
||||
} else {
|
||||
response.addHeader("Content-Type", item.format.mime)
|
||||
|
@ -49,7 +49,7 @@ class ContentController(
|
|||
ResponseEntity(fileSystemResource, HttpStatus.OK)
|
||||
}
|
||||
} ?: let {
|
||||
logger.info("Could not find item id: {}", id)
|
||||
logger.info("Could not find item id: $id")
|
||||
ResponseEntity(HttpStatus.NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue