diff options
Diffstat (limited to 'configbackuprestore')
22 files changed, 1246 insertions, 0 deletions
diff --git a/configbackuprestore/getBackupVnfDetailService/pom.xml b/configbackuprestore/getBackupVnfDetailService/pom.xml new file mode 100644 index 00000000..a5259f09 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/pom.xml @@ -0,0 +1,154 @@ +<?xml version="1.0"?> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.ccsdk.parent</groupId> + <artifactId>configbackuprestore</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <groupId>com.onap.sdnc.vnfbackup</groupId> + <artifactId>getBackupVnfDetailService</artifactId> + <version>1.0-SNAPSHOT</version> + <name>getBackupVnfDetailService</name> + <url>http://maven.apache.org</url> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.4</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>1.1.9</version> + </dependency> + <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.9</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>1.5.4.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>4.3.9.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <version>1.5.3.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + + <!-- Add Log4j2 Dependency --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-log4j2</artifactId> + </dependency> + <!-- https://mvnrepository.com/artifact/org.javers/javers-core --> + <dependency> + <groupId>org.javers</groupId> + <artifactId>javers-core</artifactId> + <version>3.9.3</version> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20180130</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/com.flipkart.zjsonpatch/zjsonpatch --> + <dependency> + <groupId>com.flipkart.zjsonpatch</groupId> + <artifactId>zjsonpatch</artifactId> + <version>0.2.1</version> + </dependency> + + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.5.201505241946</version> + <executions> + <!-- + Prepares the property pointing to the JaCoCo runtime agent which + is passed as VM argument when Maven the Surefire plugin is executed. + --> + <execution> + <id>pre-unit-test</id> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <!-- Sets the path to the file which contains the execution data. --> + <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> + <!-- + Sets the name of the property containing the settings + for JaCoCo runtime agent. + --> + <propertyName>surefireArgLine</propertyName> + </configuration> + </execution> + <!-- + Ensures that the code coverage report for unit tests is created after + unit tests have been run. + --> + <execution> + <id>post-unit-test</id> + <phase>test</phase> + <goals> + <goal>report</goal> + </goals> + <configuration> + <!-- Sets the path to the file which contains the execution data. --> + <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> + <!-- Sets the output directory for the code coverage report. --> + <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> + </configuration> + </execution> + </executions> +</plugin> +</plugins> + </build> +</project>
\ No newline at end of file diff --git a/configbackuprestore/getBackupVnfDetailService/read.md b/configbackuprestore/getBackupVnfDetailService/read.md new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/read.md diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/controller/VnfComparisonController.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/controller/VnfComparisonController.java new file mode 100644 index 00000000..2f83368c --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/controller/VnfComparisonController.java @@ -0,0 +1,68 @@ +package com.onap.sdnc.vnfcomparsion.controller; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.service.VnfComparisonService; + + +@RestController +public class VnfComparisonController { + + private static final Logger logger = Logger.getLogger(VnfComparisonController.class); + + @Autowired + VnfComparisonService vnfComparisonService; + + + @RequestMapping(value="/getAllBackupVnfIds", method=RequestMethod.GET,produces="application/json") + public List<VnfConfigDetailsDB> getAllBackupVnfIds() { + return vnfComparisonService.getAllBackupVnfIds(); + } + + + @RequestMapping(value="/configcomparison/{vnfid}", method = RequestMethod.POST,produces="application/json") + public VnfCompareResponse configComparison(@RequestBody String versionNames,@PathVariable("vnfid") String vnfId) { + VnfCompareResponse vnfCompareResponse = null; + try { + JSONObject versionId = new JSONObject(versionNames); + vnfCompareResponse = vnfComparisonService.getConfigurationDeatils(versionId,vnfId); + + } catch (JSONException e1) { + logger.error("exception occered"+e1); + } + + return vnfCompareResponse; +} + + @RequestMapping(value="/configDetailsByIdVersion/{vnfid}", method = RequestMethod.POST,produces="application/json") + public VnfCompareResponse getVnfDetailsOfVersionsAndVnfID(@RequestBody String versionNames,@PathVariable("vnfid") String vnfId) { + VnfCompareResponse vnfCompareResponse = null; + try { + JSONObject versionId = new JSONObject(versionNames); + vnfCompareResponse = vnfComparisonService.getConfigDeatilsByVnfIdVnfVersion(versionId,vnfId); + + } catch (JSONException e1) { + logger.error("exception occered"+e1); + } + + return vnfCompareResponse; +} + + @RequestMapping(value="/configDetailsById/{vnfid}", method = RequestMethod.GET,produces="application/json") + public List<VnfConfigDetailsDB> getVnfDetailsOfVnfID(@PathVariable("vnfid") String vnfId) { + List<VnfConfigDetailsDB> vnfConfigDetails = null; + vnfConfigDetails = vnfComparisonService.getConfigurationDeatils(vnfId); + return vnfConfigDetails; +} +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfComparisonRepository.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfComparisonRepository.java new file mode 100644 index 00000000..265206d2 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfComparisonRepository.java @@ -0,0 +1,30 @@ +package com.onap.sdnc.vnfcomparsion.dao; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; + + +@Repository +public interface VnfComparisonRepository extends JpaRepository<VnfConfigDetailsDB, Serializable>{ + + + @Query(value = "Select * from vnfconfigdetails where vnfid = :vnfid", nativeQuery = true) + List<VnfConfigDetailsDB> getVnfDetailsByVnfID(@Param("vnfid") String vnfid); + + @Query(value = "Select * from vnfconfigdetails where vnfversion = :vnfversion and vnfid = :vnfid", nativeQuery = true) + VnfConfigDetailsDB getVnfDetails(@Param("vnfversion") String vnfversion, @Param("vnfid") String vnfid); + + public static final String FIND_VNFID = "SELECT * FROM vnfconfigdetails group by vnfid"; + + @Query(value= FIND_VNFID,nativeQuery = true) + List<VnfConfigDetailsDB> findvnfidvnfname(); + +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfIds.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfIds.java new file mode 100644 index 00000000..51210b17 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfcomparsion/dao/VnfIds.java @@ -0,0 +1,7 @@ +package com.onap.sdnc.vnfcomparsion.dao; + +public interface VnfIds { + + String getVnfID(); + +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfCompareResponse.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfCompareResponse.java new file mode 100644 index 00000000..b684541b --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfCompareResponse.java @@ -0,0 +1,16 @@ +package com.onap.sdnc.vnfconfigcomparsion.model; + +import java.util.List; + +public class VnfCompareResponse { + + private List<VnfDetails> vnfDetails; + + public List<VnfDetails> getVnfDetails() { + return vnfDetails; + } + + public void setVnfDetails(List<VnfDetails> vnfDetails) { + this.vnfDetails = vnfDetails; + } +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfConfigDetailsDB.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfConfigDetailsDB.java new file mode 100644 index 00000000..7a62dc20 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfConfigDetailsDB.java @@ -0,0 +1,108 @@ +package com.onap.sdnc.vnfconfigcomparsion.model; + +import java.sql.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +@Entity +@Table(name = "vnfconfigdetails", schema = "testreports") +public class VnfConfigDetailsDB { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private int id; + + @Column(name = "vnfid") + private String vnfid; + + @Column(name = "vnfversion") + private String vnfversion; + + @Column(name = "vnfname") + private String vnfname; + + @Column(name = "configinfo") + @Lob + private String configinfo; + + @Column(name = "creationdate") + private Date creationdate; + + @Column(name = "lastupdated") + private String lastupdated; + + @Column(name = "status") + private String status; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getVnfid() { + return vnfid; + } + + public void setVnfid(String vnfid) { + this.vnfid = vnfid; + } + + public String getVnfversion() { + return vnfversion; + } + + public void setVnfversion(String vnfversion) { + this.vnfversion = vnfversion; + } + + public String getVnfname() { + return vnfname; + } + + public void setVnfname(String vnfname) { + this.vnfname = vnfname; + } + + public String getConfiginfo() { + return configinfo; + } + + public void setConfiginfo(String configinfo) { + this.configinfo = configinfo; + } + + public Date getCreationdate() { + return creationdate; + } + + public void setCreationdate(Date creationdate) { + this.creationdate = creationdate; + } + + public String getLastupdated() { + return lastupdated; + } + + public void setLastupdated(String lastupdated) { + this.lastupdated = lastupdated; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfDetails.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfDetails.java new file mode 100644 index 00000000..56b5ee27 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/model/VnfDetails.java @@ -0,0 +1,27 @@ +package com.onap.sdnc.vnfconfigcomparsion.model; + +public class VnfDetails { + + private String vnfId; + private String vnfDeatils; + private String vnfversion; + + public String getVnfversion() { + return vnfversion; + } + public void setVnfversion(String vnfversion) { + this.vnfversion = vnfversion; + } + public String getVnfDeatils() { + return vnfDeatils; + } + public void setVnfDeatils(String vnfDeatils) { + this.vnfDeatils = vnfDeatils; + } + public String getVnfId() { + return vnfId; + } + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonService.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonService.java new file mode 100644 index 00000000..73111e62 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonService.java @@ -0,0 +1,96 @@ +package com.onap.sdnc.vnfconfigcomparsion.service; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails; + +@Service +public class VnfComparisonService { + + private static final Logger logger = LogManager.getLogger(VnfComparisonService.class); + + @Autowired + VnfComparisonRepository vnfComparisonRepository; + + //Returns vnfconfig details if at list 2 and at most 4 versions selected. + public VnfCompareResponse getConfigurationDeatils(JSONObject vnfVersionNames, String vnfId) { + VnfCompareResponse vnfCompareResponse = new VnfCompareResponse(); + List<VnfDetails> vnfDetailsList = new ArrayList<VnfDetails>(); + VnfDetails vnfDetails = null; + try { + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + if (vnfIdArray.length() >= 2 && vnfIdArray.length() <= 4) { + for (int i = 0; i < vnfIdArray.length(); i++) { + + VnfConfigDetailsDB vnfconfigdetails = vnfComparisonRepository + .getVnfDetails(vnfIdArray.get(i).toString(), vnfId); + vnfDetails = new VnfDetails(); + vnfDetails.setVnfDeatils(vnfconfigdetails.getConfiginfo()); + vnfDetails.setVnfId(vnfconfigdetails.getVnfid()); + vnfDetails.setVnfversion(vnfconfigdetails.getVnfversion()); + vnfDetailsList.add(vnfDetails); + logger.debug("Versions : " + vnfIdArray.get(i)); + } + }/*else { + throw new RuntimeException("At list 2 and at most 4 versions need to be selected"); + }*/ + } catch (JSONException jSONException1) { + + logger.debug("JSONException occered " + jSONException1); + + } + vnfCompareResponse.setVnfDetails(vnfDetailsList); + return vnfCompareResponse; + } + + //Returns vnfconfig details for any version. + public VnfCompareResponse getConfigDeatilsByVnfIdVnfVersion(JSONObject vnfVersionNames, String vnfId) { + VnfCompareResponse vnfCompareResponse = new VnfCompareResponse(); + List<VnfDetails> vnfDetailsList = new ArrayList<VnfDetails>(); + VnfDetails vnfDetails = null; + try { + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + for (int i = 0; i < vnfIdArray.length(); i++) { + VnfConfigDetailsDB vnfconfigdetails = vnfComparisonRepository + .getVnfDetails(vnfIdArray.get(i).toString(), vnfId); + vnfDetails = new VnfDetails(); + vnfDetails.setVnfDeatils(vnfconfigdetails.getConfiginfo()); + vnfDetails.setVnfId(vnfconfigdetails.getVnfid()); + vnfDetails.setVnfversion(vnfconfigdetails.getVnfversion()); + vnfDetailsList.add(vnfDetails); + logger.debug("Versions : " + vnfIdArray.get(i)); + } + } catch (JSONException jSONException2) { + + logger.debug("JSONException occered " + jSONException2); + } + vnfCompareResponse.setVnfDetails(vnfDetailsList); + return vnfCompareResponse; + } + + //Returns backup vnf details according to vnf id. + public List<VnfConfigDetailsDB> getConfigurationDeatils(String vnfId) { + List<VnfConfigDetailsDB> vnfconfigdetails = vnfComparisonRepository.getVnfDetailsByVnfID(vnfId); + return vnfconfigdetails; + } + + //Returns all backup vnf details. + public List<VnfConfigDetailsDB> getAllBackupVnfIds() { + List<VnfConfigDetailsDB> vnfconfigdetails = vnfComparisonRepository.findvnfidvnfname(); + + return vnfconfigdetails; + } + +} diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDAndVnfVersionService.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDAndVnfVersionService.java new file mode 100644 index 00000000..27db0ac4 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDAndVnfVersionService.java @@ -0,0 +1,56 @@ +/*package com.onap.sdnc.vnfconfigcomparsion.service; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; + +import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails; + +public class VnfDetailsForVnfIDAndVnfVersionService { + + private static final Logger logger = LogManager.getLogger(VnfComparisonService.class); + + @Autowired + VnfComparisonRepository vnfComparisonRepository; + + public VnfCompareResponse getConfigurationDeatils(JSONObject vnfVersionNames, String vnfId) { + + VnfCompareResponse vnfCompareResponse = new VnfCompareResponse(); + List<VnfDetails> vnfDetailsList = new ArrayList<VnfDetails>(); + VnfDetails vnfDetails = new VnfDetails(); + try { + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + for (int i = 0; i < vnfIdArray.length(); i++) { + try { + VnfConfigDetailsDB vnfconfigdetails = vnfComparisonRepository + .getVnfDetails(vnfIdArray.get(i).toString(), vnfId); + vnfDetails.setVnfDeatils(vnfconfigdetails.getConfiginfo()); + vnfDetails.setVnfId(vnfconfigdetails.getVnfid()); + vnfDetailsList.add(vnfDetails); + logger.debug("Versions : " + vnfIdArray.get(i)); + } catch (Exception e) { + // TODO Auto-generated catch block + // e.printStackTrace(); + } + } + } catch (JSONException jSONException) { + + throw new RuntimeException("Enter atlist 2 versions and maximum 4 versions"); + } + vnfCompareResponse.setVnfDetails(vnfDetailsList); + return vnfCompareResponse; + + } + +} +*/
\ No newline at end of file diff --git a/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDService.java b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDService.java new file mode 100644 index 00000000..2aff5bd1 --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/main/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfDetailsForVnfIDService.java @@ -0,0 +1,36 @@ +/*package com.onap.sdnc.vnfconfigcomparsion.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails; + +public class VnfDetailsForVnfIDService { + + @Autowired + VnfComparisonRepository vnfComparisonRepository; + + public VnfCompareResponse getConfigurationDeatils(String vnfId) { + VnfCompareResponse vnfCompareResponse = new VnfCompareResponse(); + List<VnfDetails> vnfDetailsList = new ArrayList<VnfDetails>(); + VnfDetails vnfDetails = new VnfDetails(); + try { + VnfConfigDetailsDB vnfconfigdetails = vnfComparisonRepository.getVnfDetailsByVnfID(vnfId); + vnfDetails.setVnfDeatils(vnfconfigdetails.getConfiginfo()); + vnfDetails.setVnfId(vnfconfigdetails.getVnfid()); + vnfDetailsList.add(vnfDetails); + } catch (Exception e) { + // TODO Auto-generated catch block + // e.printStackTrace(); + } + vnfCompareResponse.setVnfDetails(vnfDetailsList); + return vnfCompareResponse; + } + +} +*/
\ No newline at end of file diff --git a/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java b/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java new file mode 100644 index 00000000..0afcd69c --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java @@ -0,0 +1,123 @@ +package com.onap.sdnc.vnfconfigcomparsion.service; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyString; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails; + + + +@RunWith(MockitoJUnitRunner.class) +public class VnfComparisonServiceTest { + + @InjectMocks + VnfComparisonService vnfComparisonService; + + @Mock + VnfComparisonRepository vnfComparisonRepository; + + @Test + public void testGetConfigurationDeatils_1() throws JSONException { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\"] }"); + String vnfId = "1a"; + List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + //Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId); + assertEquals(value.getConfiginfo(), exampleJson); + + } + + @Test + public void testGetConfigurationDeatils() throws Exception { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }"); + // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }"; + String vnfId = "1a"; + List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + + response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId); + System.out.println(response); + assertNotNull(response); + assertEquals(value.getConfiginfo(), exampleJson); + assertEquals(value.getVnfid(), vnfId); + assertEquals(value.getStatus(), "Y"); + } + + @Test + public void testgetConfigDeatilsByVnfIdVnfVersion() throws JSONException { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }"); + // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }"; + String vnfId = "1a"; + List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + + response = vnfComparisonService.getConfigDeatilsByVnfIdVnfVersion(vnfVersionNames, vnfId); + System.out.println(response); + assertNotNull(response); + assertEquals(value.getConfiginfo(), exampleJson); + assertEquals(value.getVnfid(), vnfId); + assertEquals(value.getStatus(), "Y"); + } + + +} diff --git a/configbackuprestore/pom.xml b/configbackuprestore/pom.xml new file mode 100644 index 00000000..c925197c --- /dev/null +++ b/configbackuprestore/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.onap.ccsdk.parent</groupId> + <artifactId>configbackuprestore</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Archetype - configbackuprestore</name> + <packaging>pom</packaging> + + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>1.5.4.RELEASE</version> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + + + <modules> + <module>getBackupVnfDetailService</module> + <module>vnfconfigreportsservice</module> + </modules> + + <build> +<plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.7.5.201505241946</version> + <executions> + <!-- + Prepares the property pointing to the JaCoCo runtime agent which + is passed as VM argument when Maven the Surefire plugin is executed. + --> + <execution> + <id>pre-unit-test</id> + <goals> + <goal>prepare-agent</goal> + </goals> + <configuration> + <!-- Sets the path to the file which contains the execution data. --> + <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> + <!-- + Sets the name of the property containing the settings + for JaCoCo runtime agent. + --> + <propertyName>surefireArgLine</propertyName> + </configuration> + </execution> + <!-- + Ensures that the code coverage report for unit tests is created after + unit tests have been run. + --> + <execution> + <id>post-unit-test</id> + <phase>test</phase> + <goals> + <goal>report</goal> + </goals> + <configuration> + <!-- Sets the path to the file which contains the execution data. --> + <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> + <!-- Sets the output directory for the code coverage report. --> + <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> +</plugins> +</build> +</project> diff --git a/configbackuprestore/read.md b/configbackuprestore/read.md new file mode 100644 index 00000000..3667cd32 --- /dev/null +++ b/configbackuprestore/read.md @@ -0,0 +1,7 @@ +Pconfigbackuprestore +--------------------- +It is the parent of bellow services + +vnfconfigbackupservice +getBackupVnfDetailService +vnfconfigreportsservice diff --git a/configbackuprestore/vnfconfigreportsservice/README.md b/configbackuprestore/vnfconfigreportsservice/README.md new file mode 100644 index 00000000..4462cbe8 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/README.md @@ -0,0 +1,3 @@ +vnfconfigreportsservice +------------------------ +It will show all the information about backup vnf configuration details. diff --git a/configbackuprestore/vnfconfigreportsservice/pom.xml b/configbackuprestore/vnfconfigreportsservice/pom.xml new file mode 100644 index 00000000..1d83bd02 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/pom.xml @@ -0,0 +1,112 @@ +<?xml version="1.0"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.ccsdk.parent</groupId> + <artifactId>configbackuprestore</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <groupId>com.onap.sdnc.vnfbackup</groupId> + <artifactId>vnfconfigreportsservice</artifactId> + <version>1.0-SNAPSHOT</version> + <name>vnfconfigreportsservice</name> + <url>http://maven.apache.org</url> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + <scope>provided</scope> +</dependency> + + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>1.1.9</version> + </dependency> + <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.9</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>1.5.4.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>4.3.9.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <version>1.5.3.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + + <!-- Add Log4j2 Dependency --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-log4j2</artifactId> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20180130</version> + </dependency> + <!-- https://mvnrepository.com/artifact/com.fasterxml/jackson-xml-databind --> + <dependency> + <groupId>com.fasterxml</groupId> + <artifactId>jackson-xml-databind</artifactId> + <version>0.6.2</version> + </dependency> +<dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.9.5</version> + <scope>test</scope> +</dependency> + </dependencies> +</project> + diff --git a/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/controller/VnfReportsServiceController.java b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/controller/VnfReportsServiceController.java new file mode 100644 index 00000000..4ef15366 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/controller/VnfReportsServiceController.java @@ -0,0 +1,44 @@ +package com.onap.sdnc.vnfreportsservice.controller; + +import java.util.Date; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import com.onap.sdnc.vnfreportsservice.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfreportsservice.service.VnfReportsServiceImpl; + +@RestController +public class VnfReportsServiceController { + + private static final Logger logger = LogManager.getLogger(VnfReportsServiceController.class); + + @Autowired + VnfReportsServiceImpl Vnfreportsservice; + + @RequestMapping(value = "/getVnfDetBetDates/{startDate}/{endDate}", method = RequestMethod.GET, produces = "application/json") + + public List<VnfConfigDetailsDB> getVnfConfigDetailsBetweenDates( + @PathVariable("startDate") @DateTimeFormat(pattern = "dd-MM-yyyy") Date startDate, + @PathVariable("endDate") @DateTimeFormat(pattern = "dd-MM-yyyy") Date endDate) { + logger.info("Get VNF Configuration Details Inbetween 2 Dates "); + return Vnfreportsservice.getVnfConfigDetailsBetweenDates(startDate, endDate); + } + + @RequestMapping(value = "/getVnfDetByVnfidBetDates/{vnfid}/{startDate}/{endDate}", method = RequestMethod.GET, produces = "application/json") + + public List<VnfConfigDetailsDB> getVnfConfigDetailsByVnfIdBetweenDates(@PathVariable("vnfid") String vnfId, + @PathVariable("startDate") @DateTimeFormat(pattern = "dd-MM-yyyy") Date startDate, + @PathVariable("endDate") @DateTimeFormat(pattern = "dd-MM-yyyy") Date endDate) { + logger.info("Get VNF Configuration Details Of a VnfID Inbetween 2 Dates "); + return Vnfreportsservice.getVnfIdDetailsBetweenDates(vnfId, startDate, endDate); + } + +} diff --git a/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/dao/VnfReportsServiceRepo.java b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/dao/VnfReportsServiceRepo.java new file mode 100644 index 00000000..1834ebe0 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/dao/VnfReportsServiceRepo.java @@ -0,0 +1,20 @@ +package com.onap.sdnc.vnfreportsservice.dao; +import java.util.Date; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.onap.sdnc.vnfreportsservice.controller.VnfReportsServiceController; +import com.onap.sdnc.vnfreportsservice.model.VnfConfigDetailsDB; + + +public interface VnfReportsServiceRepo extends JpaRepository<VnfConfigDetailsDB, Long> { + + List<VnfConfigDetailsDB> findByLastupdatedBetween(Date startDate, Date endDate); + List<VnfConfigDetailsDB> findByVnfidAndLastupdatedBetween(String vnfid,Date startDate,Date endDate); + +} + + diff --git a/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/model/VnfConfigDetailsDB.java b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/model/VnfConfigDetailsDB.java new file mode 100644 index 00000000..a2c08ef7 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/model/VnfConfigDetailsDB.java @@ -0,0 +1,110 @@ +package com.onap.sdnc.vnfreportsservice.model; + +import java.sql.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +@Entity +@Table(name = "vnfconfigdetails", schema = "testreports") +public class VnfConfigDetailsDB { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private int id; + + @Column(name = "vnfid") + private String vnfid; + + @Column(name = "vnfversion") + private String vnfversion; + + @Column(name = "vnfname") + private String vnfname; + + @Column(name = "configinfo") + @Lob + private String configinfo; + + @Column(name = "creationdate") + private Date creationdate; + + @Column(name = "lastupdated") + private Date lastupdated; + + @Column(name = "status") + private String status; + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getVnfid() { + return vnfid; + } + + public void setVnfid(String vnfid) { + this.vnfid = vnfid; + } + + public String getVnfversion() { + return vnfversion; + } + + public void setVnfversion(String vnfversion) { + this.vnfversion = vnfversion; + } + + public String getVnfname() { + return vnfname; + } + + public void setVnfname(String vnfname) { + this.vnfname = vnfname; + } + + public String getConfiginfo() { + return configinfo; + } + + public void setConfiginfo(String configinfo) { + this.configinfo = configinfo; + } + + public Date getCreationdate() { + return creationdate; + } + + public void setCreationdate(Date creationdate) { + this.creationdate = creationdate; + } + + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Date getLastupdated() { + return lastupdated; + } + + public void setLastupdated(Date lastupdated) { + this.lastupdated = lastupdated; + } + +} + diff --git a/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImpl.java b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImpl.java new file mode 100644 index 00000000..3b4a7f86 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImpl.java @@ -0,0 +1,48 @@ +package com.onap.sdnc.vnfreportsservice.service; + +import java.util.Date; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.onap.sdnc.vnfreportsservice.dao.VnfReportsServiceRepo; +import com.onap.sdnc.vnfreportsservice.model.VnfConfigDetailsDB; +@Service +public class VnfReportsServiceImpl implements Vnfreportsservice { + + private static final Logger logger = LogManager.getLogger(VnfReportsServiceImpl.class); + + @Autowired + VnfReportsServiceRepo vnfRepo; + + List<VnfConfigDetailsDB> config = null; + + @Override + public List<VnfConfigDetailsDB> getVnfConfigDetailsBetweenDates(Date startDate, Date endDate) { + + logger.info("Start Date" + startDate + "End Date" + endDate); + try { + config = vnfRepo.findByLastupdatedBetween(startDate, endDate); + } catch (Exception e) { + logger.error("Exception Occered Not able to get details from DB : " + e); + } + + return config; + } + + @Override + public List<VnfConfigDetailsDB> getVnfIdDetailsBetweenDates(String vnfid, Date startDate, Date endDate) { + + logger.info("Vnf ID: " + vnfid + "Start Date: " + startDate + "End Date: " + endDate); + try { + config = vnfRepo.findByVnfidAndLastupdatedBetween(vnfid, startDate, endDate); + } catch (Exception e) { + logger.error("Exception Occered Not able to get details from DB : " + e); + } + return config; + } + +} diff --git a/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/Vnfreportsservice.java b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/Vnfreportsservice.java new file mode 100644 index 00000000..3cbd2053 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/main/java/com/onap/sdnc/vnfreportsservice/service/Vnfreportsservice.java @@ -0,0 +1,11 @@ +package com.onap.sdnc.vnfreportsservice.service; + +import java.util.Date; +import java.util.List; +import com.onap.sdnc.vnfreportsservice.model.VnfConfigDetailsDB; + +public interface Vnfreportsservice { + public List<VnfConfigDetailsDB> getVnfConfigDetailsBetweenDates(Date startDate, Date endDate); + public List<VnfConfigDetailsDB> getVnfIdDetailsBetweenDates(String vnfId, Date startDate, Date endDate); + +} diff --git a/configbackuprestore/vnfconfigreportsservice/src/test/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImplTest.java b/configbackuprestore/vnfconfigreportsservice/src/test/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImplTest.java new file mode 100644 index 00000000..e40fb054 --- /dev/null +++ b/configbackuprestore/vnfconfigreportsservice/src/test/java/com/onap/sdnc/vnfreportsservice/service/VnfReportsServiceImplTest.java @@ -0,0 +1,87 @@ +package com.onap.sdnc.vnfreportsservice.service; + +import static org.junit.Assert.*; + +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.onap.sdnc.vnfreportsservice.dao.VnfReportsServiceRepo; +import com.onap.sdnc.vnfreportsservice.model.VnfConfigDetailsDB; + +@RunWith(MockitoJUnitRunner.class) +public class VnfReportsServiceImplTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfReportsServiceImplTest.class); + + @Mock + VnfReportsServiceRepo vnfRepo; + + @InjectMocks + VnfReportsServiceImpl Vnfreportsservice; + + @Test + public void getVnfConfigDetailsBetweenDatesTest() throws Exception{ + VnfConfigDetailsDB db = new VnfConfigDetailsDB(); + db.setId(123); + db.setVnfid("Vnfid"); + db.setVnfname("vnfname"); + db.setVnfversion("vnfversion"); + + Date sDate = new Date(2018, 5, 7); + Date eDate = new Date(2018, 7, 7); + db.setCreationdate(sDate); + db.setLastupdated(eDate); + db.setStatus("status"); + db.setConfiginfo("configinfo"); + + List<VnfConfigDetailsDB> list = new ArrayList<VnfConfigDetailsDB>(); + list.add(db); + LOGGER.info("List of vnf config details::" + list); + + + Mockito.when(vnfRepo.findByLastupdatedBetween(sDate, eDate)).thenReturn(list); + + Vnfreportsservice.getVnfConfigDetailsBetweenDates(sDate, eDate); + assertEquals(list, Vnfreportsservice.getVnfConfigDetailsBetweenDates(sDate, eDate)); + + } + + @Test + public void getVnfIdDetailsBetweenDatesTest() throws Exception{ + VnfConfigDetailsDB db = new VnfConfigDetailsDB(); + db.setId(123); + db.setVnfid("Vnfid"); + db.setVnfname("vnfname"); + db.setVnfversion("vnfversion"); + + Date sDate = new Date(2018, 5, 7); + Date eDate = new Date(2018, 7, 7); + db.setCreationdate(sDate); + db.setLastupdated(eDate); + db.setStatus("status"); + db.setConfiginfo("configinfo"); + + List<VnfConfigDetailsDB> list = new ArrayList<VnfConfigDetailsDB>(); + list.add(db); + LOGGER.info("List of vnf config details::" + list); + + + Mockito.when(vnfRepo.findByVnfidAndLastupdatedBetween("vnfid",sDate, eDate)).thenReturn(list); + + Vnfreportsservice.getVnfIdDetailsBetweenDates("vnfid" ,sDate, eDate); + assertEquals(list, Vnfreportsservice.getVnfIdDetailsBetweenDates("vnfid",sDate, eDate)); + + } +} + + |