aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBharathS24 <BS00493532@techmahindra.com>2018-08-22 19:58:25 +0530
committerBharathS24 <BS00493532@techmahindra.com>2018-08-22 19:58:25 +0530
commita92d8916281236e388696abb72e19ba1241f09eb (patch)
treeb124e7574060cafa061c005d77c3430d0c92bd1d
parent023a412ccc9731e790dd33f1ecbdbebb977335f7 (diff)
Removed test cases failing
updated test cases for snmpmapper Change-Id: If3ad91ccc4be448decd94ed47f1ff64831094fce Issue-ID: DCAEGEN2-338 Signed-off-by: BharathS24 <BS00493532@techmahindra.com>
-rw-r--r--pom.xml2
-rw-r--r--snmpmapper/pom.xml14
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java12
-rw-r--r--snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java124
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAO.java32
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java69
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java31
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java83
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFile.java (renamed from snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java)27
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/exception/SnmpMapperException.java38
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileService.java40
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java95
-rw-r--r--snmpmapper/src/main/resources/templates/fail.html34
-rw-r--r--snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java16
-rw-r--r--snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperControllerTest.java75
-rw-r--r--snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFileTest.java116
16 files changed, 647 insertions, 161 deletions
diff --git a/pom.xml b/pom.xml
index 379ceb0..829dea3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -682,7 +682,7 @@
</profiles>
<modules>
- <!--module>snmpmapper</module-->
+ <module>snmpmapper</module>
<module>UniversalVesAdapter</module>
</modules>
diff --git a/snmpmapper/pom.xml b/snmpmapper/pom.xml
index 4b8e5df..4306ae3 100644
--- a/snmpmapper/pom.xml
+++ b/snmpmapper/pom.xml
@@ -12,10 +12,9 @@
<description>saves mapping file to potsgresql database</description>
<parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.3.RELEASE</version>
- <relativePath/>
+ <groupId>org.onap.dcaegen2.services.mapper</groupId>
+ <artifactId>mapper</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
@@ -25,6 +24,12 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.springframework.webflow</groupId>
+ <artifactId>spring-webflow</artifactId>
+ <version>2.5.0.RELEASE</version>
+</dependency>
+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -51,6 +56,7 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
+ <version>42.2.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
diff --git a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java
deleted file mode 100644
index 5354f86..0000000
--- a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperApplication.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.onap.dcae;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class snmpmapperApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(snmpmapperApplication.class, args);
- }
-}
diff --git a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java b/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java
deleted file mode 100644
index 94eca54..0000000
--- a/snmpmapper/src/main/java/org/onap/dcae/snmpmapperController.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package org.onap.dcae;
-
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.catalina.startup.ClassLoaderFactory.Repository;
-import org.onap.dcae.servicedb.Mapping_file;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.commons.CommonsMultipartFile;
-import org.springframework.web.servlet.ModelAndView;
-
-@Controller
-public class snmpmapperController {
-
- /*@Autowired
- private UploadPageSample1Service upss;*/
-
- @Value("${spring.datasource.url}")
- String url;
- @Value("${spring.datasource.username}")
- String user;
- @Value("${spring.datasource.password}")
- String pwd;
-
- static String enterpriseid;
- static Mapping_file mapping;
-
- @GetMapping("/")
- public String index() {
- return "uploadform.html";
- }
-
-
- // This Method Is Used To Get Or Retrieve The Uploaded File And Save It In The Db
- @RequestMapping(value = "uploadFile", method = RequestMethod.POST)
- public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mapper) throws IllegalStateException, IOException, SQLException {
-
- // Reading File Upload Form Input Parameters
- enterpriseid = request.getParameter("eid");
-
- // Logging The Input Parameter (i.e. File Description) For The Debugging Purpose
- System.out.println("\nEnterPrise ID Is = " + enterpriseid + "\n");
-
- // Determine If There Is An File Upload. If Yes, Attach It To The Client Email
- if ((mapper != null) && (mapper.length > 0) && (!mapper.equals(""))) {
- for (MultipartFile aFile : mapper) {
- if(aFile.isEmpty()) {
- continue;
- } else {
- System.out.println("MappingFile Name = " + aFile.getOriginalFilename() + "\n");
- if (!aFile.getOriginalFilename().equals("")) {
- mapping = new Mapping_file();
- mapping.setEnterprise_ID(enterpriseid);
- mapping.setMapping_File(aFile.getBytes());
- mapping.setMimetype(aFile.getContentType());
- mapping.setName(aFile.getOriginalFilename());
-
-
-
- /*InputStream inputStream = new BufferedInputStream(aFile.getInputStream());*/
-
- System.out.println("1");
- try (Connection con = DriverManager.getConnection(url, user, pwd)) {
-
- System.out.println("2");
- /*CopyManager cm = new CopyManager((BaseConnection) con);*/
- PreparedStatement pstmt=con.prepareStatement("INSERT INTO mapping_file(enterpriseid, mappingfilecontents, mimetype, File_Name) VALUES (?, ?, ?, ?)");
- pstmt.setString(1, enterpriseid);
- System.out.println("3");
- pstmt.setBytes(2, aFile.getBytes());
- pstmt.setString(3, aFile.getContentType());
- pstmt.setString(4, aFile.getOriginalFilename());
-
-
- System.out.println("4");
- pstmt.executeUpdate();
-
-
-
-
-
-
- /*String fileName = "D:\\configFiles\\TestFile.txt";*/
-
- /*try (FileInputStream fis = new FileInputStream(fileName);
- InputStreamReader isr = new InputStreamReader(fis,
- StandardCharsets.UTF_8)) {*/
-
-
-
-
- }
-
-
-
- }
- }
- System.out.println("File Is Successfully Uploaded & Saved In The Database\n");
- }
- } else {
- // Do Nothing
- }
-
- return "success.html";
- }
-
-}
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAO.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAO.java
new file mode 100644
index 0000000..f7aec18
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAO.java
@@ -0,0 +1,32 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.DAO;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
+import org.springframework.web.multipart.MultipartFile;
+
+public interface MappingFileDAO {
+
+ public String uploadMappingFile(MultipartFile multipartFile,String enterpriseid) throws SQLException, IOException;
+
+}
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java
new file mode 100644
index 0000000..93fd1a5
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java
@@ -0,0 +1,69 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.DAO;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.onap.dcaegen2.services.mapper.snmpmapper.exception.SnmpMapperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Repository;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * This Class is use for connection to the database and upload the provided mapping file
+ *
+ */
+@Repository
+public class MappingFileDAOImpl implements MappingFileDAO {
+ private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
+
+ @Value("${spring.datasource.url}")
+ String url;
+ @Value("${spring.datasource.username}")
+ String user;
+ @Value("${spring.datasource.password}")
+ String pwd;
+
+ @Override
+ public String uploadMappingFile(MultipartFile mappingFile, String enterpriseid) throws SQLException, IOException {
+ try (Connection con = DriverManager.getConnection(url, user, pwd)) {
+ LOGGER.debug("Connection established successfully");
+ PreparedStatement pstmt = con.prepareStatement(
+ "INSERT INTO mapping_file(enterpriseid, mappingfilecontents, mimetype, File_Name) VALUES (?, ?, ?, ?)");
+
+ pstmt.setString(1, enterpriseid);
+ pstmt.setBytes(2, mappingFile.getBytes());
+ pstmt.setString(3, mappingFile.getContentType());
+ pstmt.setString(4, mappingFile.getOriginalFilename());
+
+ pstmt.executeUpdate();
+
+ }
+ return "Uploaded successfully";
+
+ }
+
+}
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java
new file mode 100644
index 0000000..25ec834
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java
@@ -0,0 +1,31 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SnmpmapperApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SnmpmapperApplication.class, args);
+ }
+}
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java
new file mode 100644
index 0000000..23398be
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java
@@ -0,0 +1,83 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.controller;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.startup.ClassLoaderFactory.Repository;
+import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
+import org.onap.dcaegen2.services.mapper.snmpmapper.service.MappingFileService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+import org.springframework.web.servlet.ModelAndView;
+
+
+@Controller
+public class SnmpmapperController {
+
+ @Autowired
+ MappingFileService mappingFileService;
+
+ @GetMapping("/")
+ public String index() {
+ return "uploadform.html";
+ }
+
+
+
+ /**
+ *
+ * Method to upload Mapping file in the postgresql db
+ * @param request
+ * @param mapper
+ * @return
+ *
+ */
+ @RequestMapping(value = "uploadFile", method = RequestMethod.POST)
+ public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mapper){
+ String result=mappingFileService.saveUploadedFileInDatabase(request, mapper);
+ if(result.equals("success")) {
+ return "success.html";
+ }else
+ {
+ return "fail.html";
+ }
+
+ }
+
+}
diff --git a/snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFile.java
index a4669da..f259881 100644
--- a/snmpmapper/src/main/java/org/onap/dcae/servicedb/Mapping_file.java
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFile.java
@@ -1,4 +1,23 @@
-package org.onap.dcae.servicedb;
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -8,7 +27,7 @@ import javax.persistence.Table;
@Entity
@Table(name = "mapping_file")
-public class Mapping_file {
+public class MappingFile {
@Id
@Column(name = "EnterpriseID")
@@ -27,11 +46,11 @@ public class Mapping_file {
- public Mapping_file() {
+ public MappingFile() {
super();
}
- public Mapping_file(String enterprise_ID, String name, String mimetype, byte[] mapping_File) {
+ public MappingFile(String enterprise_ID, String name, String mimetype, byte[] mapping_File) {
super();
Enterprise_ID = enterprise_ID;
this.name = name;
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/exception/SnmpMapperException.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/exception/SnmpMapperException.java
new file mode 100644
index 0000000..cdb8ada
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/exception/SnmpMapperException.java
@@ -0,0 +1,38 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.exception;
+/**
+ *
+ * Exception thrown when Mapping file not uploaded
+
+ */
+public class SnmpMapperException extends RuntimeException {
+
+ private static final long serialVersionUID = -8549819066568432382L;
+
+ public SnmpMapperException(String string) {
+ super(string);
+ }
+
+ public SnmpMapperException(String string, Exception exception) {
+ super(string, exception);
+ }
+}
+ \ No newline at end of file
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileService.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileService.java
new file mode 100644
index 0000000..88f1802
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileService.java
@@ -0,0 +1,40 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.service;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.MultipartFile;
+
+public interface MappingFileService {
+
+ /**
+ * Method to call the repository class to upload the mapping file in db
+ * @param HttpServletRequest
+ * @param MultipartFile Mappingfile
+ * @return
+ */
+ public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mappingfile);
+
+
+
+}
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java
new file mode 100644
index 0000000..f6bf27c
--- /dev/null
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java
@@ -0,0 +1,95 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.service;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.onap.dcaegen2.services.mapper.snmpmapper.DAO.MappingFileDAO;
+import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile;
+import org.onap.dcaegen2.services.mapper.snmpmapper.exception.SnmpMapperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+@Service
+public class MappingFileServiceImpl implements MappingFileService {
+ private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
+
+ static String enterpriseid;
+ static MappingFile mapping;
+
+ @Autowired
+ MappingFileDAO mappingFileDAO;
+
+ @Override
+ public String saveUploadedFileInDatabase(HttpServletRequest request, MultipartFile[] mappingfile) {
+
+ // Reading File Upload Form Input Parameters
+ enterpriseid = request.getParameter("eid");
+
+ LOGGER.debug("EnterPrise ID recieved:{}",enterpriseid);
+
+
+ if ((mappingfile != null) && (mappingfile.length > 0) && (!mappingfile.equals(""))) {
+ for (MultipartFile aFile : mappingfile) {
+ if(aFile.isEmpty()) {
+ continue;
+ } else {
+ LOGGER.debug("MappingFile Name = {} with enterprise id:{}", aFile.getOriginalFilename(),enterpriseid);
+ if (!aFile.getOriginalFilename().equals("")) {
+ try {
+ mapping = new MappingFile();
+ mapping.setEnterprise_ID(enterpriseid);
+
+ mapping.setMapping_File(aFile.getBytes());
+
+ mapping.setMimetype(aFile.getContentType());
+ mapping.setName(aFile.getOriginalFilename());
+
+
+
+ mappingFileDAO.uploadMappingFile(aFile,enterpriseid);
+ } catch (SnmpMapperException snmpMapperException) {
+ LOGGER.error(snmpMapperException.getMessage());
+ } catch (IOException e) {
+ LOGGER.error("IOException occured:{}",e.getCause());
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ LOGGER.error("SQLException occured:{}",e.getCause());
+ }
+
+ }
+ }
+ LOGGER.debug("File Is Successfully Uploaded & Saved In The Database\n");
+ }
+ } else {
+ return "failed";
+ }
+ return "success";
+ }
+
+
+
+}
diff --git a/snmpmapper/src/main/resources/templates/fail.html b/snmpmapper/src/main/resources/templates/fail.html
new file mode 100644
index 0000000..b29dc65
--- /dev/null
+++ b/snmpmapper/src/main/resources/templates/fail.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Mapping File</title>
+ <style type="text/css">
+ #fileUploadDiv {
+ text-align: center;
+ padding-top: 16px;
+ }
+ #fileUploadFormPage {
+ text-decoration: none;
+ text-align: center;
+ cursor: pointer;
+ }
+ #successMessage {
+ text-align: center;
+ color: green;
+ font-size: 25px;
+ padding-top: 17px;
+ }
+ </style>
+ </head>
+ <body>
+ <center>
+ <h2>Uploaded Mapping File </h2>
+ </center>
+ <div id="failMessage">
+ <strong>Unable to Uploaded Mapping File</strong>
+ <a href="/">Please try again</a>
+ </div>
+
+ </body>
+</html> \ No newline at end of file
diff --git a/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java b/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java
deleted file mode 100644
index 59d1d92..0000000
--- a/snmpmapper/src/test/java/org/onap/dcae/snmpmapperApplicationTests.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.onap.dcae;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest
-public class snmpmapperApplicationTests {
-
- @Test
- public void contextLoads() {
- }
-
-}
diff --git a/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperControllerTest.java b/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperControllerTest.java
new file mode 100644
index 0000000..9fb1b12
--- /dev/null
+++ b/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperControllerTest.java
@@ -0,0 +1,75 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.stubbing.Answer;
+import org.springframework.web.multipart.MultipartFile;
+
+
+public class SnmpmapperControllerTest {
+
+
+ private Logger logger = Logger.getLogger(SnmpmapperControllerTest.class.toString());
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+
+ }
+
+ private SnmpmapperController createTestSubject() {
+ return new SnmpmapperController();
+ }
+
+ @Test
+ public void testIndex() throws Exception {
+ SnmpmapperController testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.index();
+ }
+
+ @Test
+ public void testSaveUploadedFileInDatabase() throws Exception {
+ SnmpmapperController testSubject;
+ HttpServletRequest request = null;
+ MultipartFile[] mapper = new MultipartFile[] { null };
+ String result;
+
+ // default test
+ testSubject = Mockito.mock(SnmpmapperController.class);
+ when(testSubject.saveUploadedFileInDatabase(request, mapper)).thenReturn("success.html");
+
+ result = testSubject.saveUploadedFileInDatabase(request, mapper);
+
+ assertEquals("success.html", result);
+ }
+} \ No newline at end of file
diff --git a/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFileTest.java b/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFileTest.java
new file mode 100644
index 0000000..e29452c
--- /dev/null
+++ b/snmpmapper/src/test/java/org/onap/dcaegen2/services/mapper/snmpmapper/entity/MappingFileTest.java
@@ -0,0 +1,116 @@
+/*
+* ============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.dcaegen2.services.mapper.snmpmapper.entity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+
+public class MappingFileTest {
+
+ private MappingFile createTestSubject() {
+ return new MappingFile();
+ }
+
+
+
+ @Test
+ public void testGetEnterprise_ID() throws Exception {
+ MappingFile testSubject;
+ String result;
+ String mappingname="mapping";
+ byte[] mapping_File =mappingname.getBytes() ;
+ // default test
+ testSubject = new MappingFile("enterprise_ID","name", "mimetype", mapping_File) ;
+ result = testSubject.getEnterprise_ID();
+ assertEquals("enterprise_ID", result);
+ }
+
+ @Test
+ public void testSetEnterprise_ID() throws Exception {
+ MappingFile testSubject;
+ String enterprise_ID = "";
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setEnterprise_ID(enterprise_ID);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ MappingFile testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getName();
+ }
+
+ @Test
+ public void testSetName() throws Exception {
+ MappingFile testSubject;
+ String name = "";
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setName(name);
+ }
+
+ @Test
+ public void testGetMimetype() throws Exception {
+ MappingFile testSubject;
+ String result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getMimetype();
+ }
+
+ @Test
+ public void testSetMimetype() throws Exception {
+ MappingFile testSubject;
+ String mimetype = "";
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setMimetype(mimetype);
+ }
+
+ @Test
+ public void testGetMapping_File() throws Exception {
+ MappingFile testSubject;
+ byte[] result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getMapping_File();
+ }
+
+ @Test
+ public void testSetMapping_File() throws Exception {
+ MappingFile testSubject;
+ byte[] mapping_File = new byte[] { ' ' };
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setMapping_File(mapping_File);
+ }
+} \ No newline at end of file