aboutsummaryrefslogtreecommitdiffstats
path: root/snmpmapper/src
diff options
context:
space:
mode:
authorBharathS24 <BS00493532@techmahindra.com>2018-03-29 18:07:27 +0530
committerBharathS24 <BS00493532@techmahindra.com>2018-03-29 18:08:01 +0530
commit2f9bc9bfafa44607d38772afb6163d1b5919d1aa (patch)
tree25cfd0daeb9692febb82536b6174db5cdc9fa504 /snmpmapper/src
parent7d7d7a09088944d652735ef2ad7b58b81989174e (diff)
Added test cases for snmpmapper in Mapper
Commiting test cases in Mapper Change-Id: I429d66260151b5a26aa432b729c57bd6de9f0183 Issue-ID: DCAEGEN2-338 Signed-off-by: BharathS24 <BS00493532@techmahindra.com>
Diffstat (limited to 'snmpmapper/src')
-rw-r--r--snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java6
-rw-r--r--snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java101
2 files changed, 79 insertions, 28 deletions
diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java
index 74b5826..d970724 100644
--- a/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java
+++ b/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java
@@ -67,7 +67,7 @@ public class FileUploadControllerTest {
@Test
- public void test() throws Exception {
+ public void listUploadedFilesTest() throws Exception {
Model map = new ExtendedModelMap();
@@ -79,7 +79,7 @@ public class FileUploadControllerTest {
try {
Mockito.when(storageService.loadAll()).thenReturn(list.stream());
} catch (Exception e) {
-// eLOGGER.error("Error occurred : " + e.getMessage());
+
}
try {
@@ -87,7 +87,7 @@ public class FileUploadControllerTest {
assertEquals("uploadForm", listUploadedFiles);
} catch (IOException e) {
- // TODO Auto-generated catch block
+
e.printStackTrace();
}
diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java
index f80ecf7..56fc518 100644
--- a/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java
+++ b/snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java
@@ -21,8 +21,16 @@ package org.onap.dcae.mapper.storage;
import static org.junit.Assert.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
import java.nio.file.Path;
-
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,59 +43,102 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.core.io.Resource;
+import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.multipart.MultipartFile;
+
@RunWith(SpringRunner.class)
-@WebMvcTest(value = FileUploadController.class, secure = false)
+@SpringBootTest(classes=SnmpmapperApplication.class)
public class FileSystemStorageServiceTest {
StorageProperties sp = new StorageProperties();
-
- //FileSystemStorageService service = new FileSystemStorageService(sp);
+ @Autowired
+ FileSystemStorageService fileSystemStorageService ;
-//
-// @Before
-// public void init() {
-// MockitoAnnotations.initMocks(this);
-// }
-//
@Value("${fileService.rootPath}")
private String location;
+
- @Autowired
- private MockMvc mockMvc;
+ byte[] content = null;
- @Mock
- MultipartFile file;
+
- @MockBean
- private FileSystemStorageService fileSystemStorageService;
+
+
String filename;
@Test
- public void testFileSystemStorageService() {
-
- fileSystemStorageService.init();
- fileSystemStorageService.load(filename);
+ public void testFileSystemStorageServiceLoadMethod() throws IOException {
+ fileSystemStorageService.init();
+ saveFile();
+ Path filePath = fileSystemStorageService.load("TestFile.txt");
+
+ assertEquals(Paths.get(location), filePath.getParent());
+
}
+
+
@Test
- public void test() {
- Path rootLocation = null;;
- sp.setLocation(location);
- FileSystemStorageService fss=new FileSystemStorageService(sp);
+ public void storeTest() throws IOException
+ {
+ fileSystemStorageService.init();
+ saveFile();
+
+ assertEquals(true, Files.exists(Paths.get(location, "TestFile.txt")));
+
+
+
+
+
+ }
+
+ private void saveFile() throws IOException {
+ Files.deleteIfExists(Paths.get(location, "TestFile.txt"));
+ content = "randomString".getBytes();
+ MultipartFile file=new MockMultipartFile("TestFile.txt","TestFile.txt", "text/plain", content);
+
+
+ fileSystemStorageService.store(file);
+ }
+ @Test
+ public void testFileSystemStorageServiceLoadAllMethod() throws IOException {
+ fileSystemStorageService.init();
+ saveFile();
+
+ Stream<Path> filePath = fileSystemStorageService.loadAll();
+ List<Path> listOfPaths =filePath.collect(Collectors.toList());
+
+ assertEquals(true, listOfPaths.contains(Paths.get("TestFile.txt")));
+
+
+ }
+
+ @Test
+ public void testFileSystemStorageServiceLoadResourceMethod() throws IOException {
+ fileSystemStorageService.init();
+ saveFile();
+
+
+
+ Resource fileResource = fileSystemStorageService.loadAsResource("TestFile.txt");
-}
+
+ assertEquals(Paths.get(location,"TestFile.txt").getFileName().toString(), fileResource.getFilename());
+
+
+ }
} \ No newline at end of file