Added test cases for snmpmapper in Mapper 65/39665/2
authorBharathS24 <BS00493532@techmahindra.com>
Wed, 28 Mar 2018 13:54:29 +0000 (19:24 +0530)
committerBharathS24 <BS00493532@techmahindra.com>
Wed, 28 Mar 2018 13:56:19 +0000 (19:26 +0530)
Commiting test cases in Mapper

Change-Id: Icd60a8a94400c1b95d26f0bfd7feeb46900a5db7
Issue-ID: DCAEGEN2-338
Signed-off-by: BharathS24 <BS00493532@techmahindra.com>
snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java [new file with mode: 0644]
snmpmapper/src/test/java/org/onap/dcae/mapper/storage/FileSystemStorageServiceTest.java [new file with mode: 0644]

diff --git a/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java b/snmpmapper/src/test/java/org/onap/dcae/mapper/FileUploadControllerTest.java
new file mode 100644 (file)
index 0000000..74b5826
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : DCAE
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package org.onap.dcae.mapper;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcae.mapper.storage.StorageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.ui.ExtendedModelMap;
+import org.springframework.ui.Model;
+import org.springframework.web.servlet.ModelAndView;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes=SnmpmapperApplication.class)
+@AutoConfigureMockMvc
+
+public class FileUploadControllerTest {
+
+    @Autowired
+    private MockMvc mockMvc;
+    
+    @Mock
+    private StorageService storageService;
+    
+    @Autowired
+    @InjectMocks
+    private FileUploadController fuc;
+    
+    @Before
+    public void init() {
+        MockitoAnnotations.initMocks(this);
+    } 
+    
+    
+    @Test
+    public void test() throws Exception {
+        
+        Model map = new ExtendedModelMap();
+        
+        Path p1 = Paths.get(".");
+        List<Path> list = new ArrayList<>();
+        list.add(p1);
+        
+        
+        try {
+            Mockito.when(storageService.loadAll()).thenReturn(list.stream());
+        } catch (Exception e) {
+//            eLOGGER.error("Error occurred : " + e.getMessage());
+        }
+       
+        try {
+            String listUploadedFiles = fuc.listUploadedFiles(map);
+            
+            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
new file mode 100644 (file)
index 0000000..f80ecf7
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : DCAE
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package org.onap.dcae.mapper.storage;
+
+import static org.junit.Assert.*;
+
+import java.nio.file.Path;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcae.mapper.FileUploadController;
+import org.onap.dcae.mapper.SnmpmapperApplication;
+import org.springframework.beans.factory.annotation.Autowired;
+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.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)
+public class FileSystemStorageServiceTest {
+    
+    
+  
+    StorageProperties sp = new StorageProperties();
+     
+    //FileSystemStorageService service = new FileSystemStorageService(sp);
+
+    
+//    
+//    @Before
+//    public void init() {
+//        MockitoAnnotations.initMocks(this);
+//    }
+//    
+    
+    @Value("${fileService.rootPath}")
+    private String location;
+    
+    
+    @Autowired
+    private MockMvc mockMvc;
+    
+    @Mock
+    MultipartFile file;
+    
+    @MockBean
+    private FileSystemStorageService fileSystemStorageService;
+    String filename;
+    
+    
+    @Test
+    public void testFileSystemStorageService() {
+        
+        fileSystemStorageService.init();
+        fileSystemStorageService.load(filename);
+        
+       
+    }
+    
+    @Test
+    public void test() {
+         Path rootLocation = null;;
+        sp.setLocation(location);
+        FileSystemStorageService fss=new FileSystemStorageService(sp);
+
+}
+    
+}
\ No newline at end of file