-
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.
- Loading branch information
martin
authored and
martin
committed
Mar 10, 2020
1 parent
0846d59
commit 308778c
Showing
6 changed files
with
144 additions
and
29 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
97 changes: 97 additions & 0 deletions
97
storage-cloud-filesystem/src/test/java/it/cnr/si/spring/storage/CreateAndDeleteTest.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,97 @@ | ||
package it.cnr.si.spring.storage; | ||
|
||
import static it.cnr.si.spring.storage.FilesystemTestUtils.PIPPO; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.math.BigInteger; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import it.cnr.si.spring.storage.config.StoragePropertyNames; | ||
|
||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration("classpath:storage-filesystem-test-context.xml") | ||
@TestPropertySource("classpath:META-INF/spring/filesystem.properties") | ||
public class CreateAndDeleteTest { | ||
|
||
private final Logger log = LoggerFactory.getLogger(CreateAndDeleteTest.class); | ||
|
||
@Autowired | ||
private StoreService storeService; | ||
@Autowired | ||
private FilesystemTestUtils filesystemTestUtils; | ||
|
||
@Value("${cnr.storage.filesystem.directory}") | ||
private String baseDir; | ||
|
||
@Test | ||
public void testCreateAndReadSimpleDocumentAndMetadata() { | ||
InputStream is = new ByteArrayInputStream(PIPPO.getBytes()); | ||
String contentType = "text/plain"; | ||
String path = ""; | ||
Map<String, Object> metadata = new HashMap<>(); | ||
StorageObject so = storeService.storeSimpleDocument(is, contentType, path, metadata); | ||
|
||
StorageObject tre = storeService.getStorageObjectBykey(so.getKey()); | ||
StorageObject quattro = storeService.getStorageObjectByPath(so.getPath()); | ||
|
||
log.info("{}", so); | ||
log.info("{}", tre); | ||
log.info("{}", quattro); | ||
|
||
assertEquals(so.toString(), tre.toString()); | ||
assertEquals(so.toString(), quattro.toString()); | ||
assertEquals(so.getPath(), tre.getPath()); | ||
assertEquals(so.getKey(), tre.getKey()); | ||
|
||
InputStream content = storeService.getResource(so.getKey()); | ||
so = storeService.getStorageObjectBykey(so.getKey()); | ||
BigInteger length= so.<BigInteger>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_LENGTH.value()); | ||
String ctype = so.<String>getPropertyValue(StoragePropertyNames.CONTENT_STREAM_MIME_TYPE.value()); | ||
assertNotEquals(length,0); | ||
assertNotNull(ctype); | ||
|
||
String contentString = new Scanner(content).next(); | ||
|
||
log.info("{}", contentString); | ||
|
||
assertEquals(PIPPO, contentString); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void testDeleteFile() { | ||
|
||
StorageObject so = filesystemTestUtils.createFile(); | ||
|
||
so = storeService.getStorageObjectBykey(so.getKey()); | ||
assertTrue( storeService.delete(so.getKey()) ); | ||
assertNull( storeService.getStorageObjectBykey(so.getKey()) ); | ||
|
||
assertFalse(Files.exists( Paths.get(baseDir, so.getPath()) )); | ||
assertFalse(Files.exists( Paths.get(baseDir, so.getPath() + ".properties") )); | ||
|
||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
storage-cloud-filesystem/src/test/java/it/cnr/si/spring/storage/FilesystemTestUtils.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,35 @@ | ||
package it.cnr.si.spring.storage; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import it.cnr.si.spring.storage.bulk.StorageFile; | ||
|
||
@Component | ||
public class FilesystemTestUtils { | ||
|
||
/*friendly*/ static final String PIPPO = "pippo", | ||
PLUTO = "pluto"; | ||
|
||
@Autowired | ||
private StoreService storeService; | ||
|
||
/*friendly*/ StorageObject createFile() { | ||
InputStream is = new ByteArrayInputStream(PIPPO.getBytes()); | ||
|
||
StorageFile file = new StorageFile(is, | ||
"text/plain", | ||
"Titolo"); | ||
|
||
return storeService.restoreSimpleDocument( | ||
file, | ||
new ByteArrayInputStream(file.getBytes()), | ||
"text/plain", | ||
"Titolo", | ||
"/", | ||
true); | ||
} | ||
} |
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