-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from clarin-eric/utf8encoding
Set content-encoding for text utf8 files
- Loading branch information
Showing
6 changed files
with
192 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
backend/src/test/java/eu/clarin/switchboard/core/DataStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
backend/src/test/java/eu/clarin/switchboard/resources/DataResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package eu.clarin.switchboard.resources; | ||
|
||
import com.google.common.io.ByteStreams; | ||
import eu.clarin.switchboard.app.config.DataStoreConfig; | ||
import eu.clarin.switchboard.app.config.UrlResolverConfig; | ||
import eu.clarin.switchboard.core.DataStore; | ||
import eu.clarin.switchboard.core.DefaultStoragePolicy; | ||
import eu.clarin.switchboard.core.MediaLibrary; | ||
import eu.clarin.switchboard.profiler.DefaultProfiler; | ||
import eu.clarin.switchboard.profiler.api.Profile; | ||
import eu.clarin.switchboard.profiler.api.Profiler; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.StreamingOutput; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class DataResourceTest { | ||
DataResource dataResource; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Path dataStoreRoot = Files.createTempDirectory("switchboard-test-"); | ||
String maxSize = "1M"; | ||
String maxFiles = "2"; | ||
String maxLifetime = "4"; | ||
String maxLifetimeUnit = "seconds"; | ||
String cleanupPeriod = "1"; | ||
String cleanupPeriodUnit = "seconds"; | ||
|
||
DataStoreConfig dataStoreConfig = new DataStoreConfig( | ||
dataStoreRoot.toString(), false, maxSize, maxFiles, maxLifetime, maxLifetimeUnit, cleanupPeriod, cleanupPeriodUnit); | ||
|
||
DefaultStoragePolicy storagePolicy = new DefaultStoragePolicy(dataStoreConfig); | ||
storagePolicy.setAllowedMediaTypes(Collections.singleton("text/plain")); | ||
|
||
DataStore dataStore = new DataStore(dataStoreRoot, storagePolicy); | ||
Profiler profiler = new DefaultProfiler(); | ||
UrlResolverConfig urlResolver = new UrlResolverConfig(3, 3, "seconds", 10); | ||
MediaLibrary mediaLibrary = new MediaLibrary(dataStore, profiler, storagePolicy, urlResolver, dataStoreConfig); | ||
dataResource = new DataResource(mediaLibrary); | ||
} | ||
|
||
|
||
@Test | ||
public void getFile() throws Throwable { | ||
InputStream is = new ByteArrayInputStream("first content".getBytes(StandardCharsets.UTF_8)); | ||
|
||
Response postResponse = dataResource.postFile("", is, "filename", null, null, null, null); | ||
String id = ((Map) postResponse.getEntity()).get("id").toString(); | ||
|
||
Response r = dataResource.getFile(id, null); | ||
assertEquals("text/plain;charset=utf-8", r.getHeaderString("content-type")); | ||
} | ||
|
||
@Test | ||
public void getFileInfo() throws Throwable { | ||
String filename = "myfilename"; | ||
InputStream is = new ByteArrayInputStream("first content".getBytes(StandardCharsets.UTF_8)); | ||
|
||
Response postResponse = dataResource.postFile("", is, filename, null, null, null, null); | ||
String id = ((Map) postResponse.getEntity()).get("id").toString(); | ||
|
||
Response r = dataResource.getFileInfo("/info", id); | ||
Map fileinfo = ((Map) r.getEntity()); | ||
|
||
assertEquals(id, fileinfo.get("id").toString()); | ||
assertEquals(filename, fileinfo.get("filename").toString()); | ||
assertTrue((int)fileinfo.get("fileLength") > 0); | ||
assertFalse((boolean)fileinfo.get("selection")); | ||
assertEquals("text/plain", ((Map)fileinfo.get("profile")).get("mediaType")); | ||
} | ||
|
||
@Test | ||
public void putContent() throws Throwable { | ||
String newContent = "new content"; | ||
InputStream is = new ByteArrayInputStream("first content".getBytes(StandardCharsets.UTF_8)); | ||
|
||
Response postResponse = dataResource.postFile("", is, "filename", null, null, null, null); | ||
String id = ((Map) postResponse.getEntity()).get("id").toString(); | ||
|
||
dataResource.putContent(id, newContent); | ||
|
||
Response r = dataResource.getFile(id, null); | ||
StreamingOutput output = (StreamingOutput) r.getEntity(); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
output.write(baos); | ||
assertEquals(newContent, baos.toString()); | ||
} | ||
} |
Submodule profiler
updated
13 files