diff --git a/src/test/java/org/nvip/api/serializers/CvssDTOTest.java b/src/test/java/org/nvip/api/serializers/CvssDTOTest.java new file mode 100644 index 0000000..734a918 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/CvssDTOTest.java @@ -0,0 +1,27 @@ +package org.nvip.api.serializers; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; +public class CvssDTOTest { + + @Test + public void testGettersAndSetters() { + CvssDTO cvssDTO = new CvssDTO("CVE-2343",3.0); + cvssDTO.setCveId("CVE-1234"); + cvssDTO.setBaseScore(5.0); + + assertEquals("CVE-1234", cvssDTO.getCveId()); + assertEquals(5.0, cvssDTO.getBaseScore(),0.0003f); + } + + @Test + public void testBuilder() { + CvssDTO cvssDTO = CvssDTO.builder() + .cveId("CVE-1234") + .baseScore(5.0) + .build(); + + assertEquals("CVE-1234", cvssDTO.getCveId()); + assertEquals(5.0, cvssDTO.getBaseScore(),0.0003f); + } +} diff --git a/src/test/java/org/nvip/api/serializers/DescriptionDTOTest.java b/src/test/java/org/nvip/api/serializers/DescriptionDTOTest.java new file mode 100644 index 0000000..50060d5 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/DescriptionDTOTest.java @@ -0,0 +1,33 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class DescriptionDTOTest { + + @Test + public void testGettersAndSetters() { + DescriptionDTO descriptionDTO = new DescriptionDTO("old description","old createdDate",0); + descriptionDTO.setDescription("New Description"); + descriptionDTO.setCreatedDate("New CreatedDate"); + descriptionDTO.setIsUserGenerated(1); + + assertEquals("New Description", descriptionDTO.getDescription()); + assertEquals("New CreatedDate",descriptionDTO.getCreatedDate()); + assertEquals(1,descriptionDTO.getIsUserGenerated()); + } + + @Test + public void testBuilder() { + DescriptionDTO descriptionDTO = DescriptionDTO.builder() + .description("New Description") + .createdDate("New CreatedDate") + .isUserGenerated(1) + .build(); + + assertEquals("New Description", descriptionDTO.getDescription()); + assertEquals("New CreatedDate",descriptionDTO.getCreatedDate()); + assertEquals(1,descriptionDTO.getIsUserGenerated()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/ExploitDTOTest.java b/src/test/java/org/nvip/api/serializers/ExploitDTOTest.java new file mode 100644 index 0000000..8d40103 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/ExploitDTOTest.java @@ -0,0 +1,62 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class ExploitDTOTest { + + @Test + public void testGettersAndSetters() { + ExploitDTO exploitDTO = new ExploitDTO(0,"old name","old description", "old example_file","old author","old date_published",false,"old source","old dateCreated",false,"0","old sourceURL"); + exploitDTO.setExploitId(1); + exploitDTO.setName("new name"); + exploitDTO.setDescription("new description"); + exploitDTO.setExample_file("new example_file"); + exploitDTO.setAuthor("new author"); + exploitDTO.setDatePublished("new date_published"); + exploitDTO.setSource("new source"); + exploitDTO.setDateCreated("new dateCreated"); + exploitDTO.setDownloadFailed(true); + exploitDTO.setCveId("1"); + exploitDTO.setSourceUrl("new SourceUrl"); + + assertEquals(1, exploitDTO.getExploitId()); + assertEquals("new name", exploitDTO.getName()); + assertEquals("new description", exploitDTO.getDescription()); + assertEquals("new example_file", exploitDTO.getExample_file()); + assertEquals("new author", exploitDTO.getAuthor()); + assertEquals("new date_published", exploitDTO.getDatePublished()); + assertEquals("1", exploitDTO.getCveId()); + assertEquals("new source", exploitDTO.getSource()); + assertEquals("new SourceUrl", exploitDTO.getSourceUrl()); + + } + + @Test + public void testBuilder() { + ExploitDTO exploitDTO = ExploitDTO.builder() + .exploitId(1) + .name("new name") + .description("new description") + .example_file("new example_file") + .author("new author") + .datePublished("new date_published") + .source("new source") + .dateCreated("new dateCreated") + .downloadFailed(true) + .cveId("1") + .sourceUrl("new SourceUrl") + .build(); + + assertEquals(1, exploitDTO.getExploitId()); + assertEquals("new name", exploitDTO.getName()); + assertEquals("new description", exploitDTO.getDescription()); + assertEquals("new example_file", exploitDTO.getExample_file()); + assertEquals("new author", exploitDTO.getAuthor()); + assertEquals("new date_published", exploitDTO.getDatePublished()); + assertEquals("1", exploitDTO.getCveId()); + assertEquals("new source", exploitDTO.getSource()); + assertEquals("new SourceUrl", exploitDTO.getSourceUrl()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/FixDTOTest.java b/src/test/java/org/nvip/api/serializers/FixDTOTest.java new file mode 100644 index 0000000..ebb8dfb --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/FixDTOTest.java @@ -0,0 +1,31 @@ +package org.nvip.api.serializers; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class FixDTOTest { + @Test + public void testGettersAndSetters() { + FixDTO fixDTO = new FixDTO("old cveid","old sourceUrl","old fixDescription"); + fixDTO.setCveId("new cveid"); + fixDTO.setSourceUrl("new sourceUrl"); + fixDTO.setFixDescription("new fixDescription"); + + assertEquals("new cveid", fixDTO.getCveId()); + assertEquals("new sourceUrl", fixDTO.getSourceUrl()); + assertEquals("new fixDescription", fixDTO.getFixDescription()); + } + + @Test + public void testBuilder() { + FixDTO fixDTO = new FixDTO.FixDTOBuilder() + .cveId("new cveid") + .sourceUrl("new sourceUrl") + .fixDescription("new fixDescription") + .build(); + + assertEquals("new cveid", fixDTO.getCveId()); + assertEquals("new sourceUrl", fixDTO.getSourceUrl()); + assertEquals("new fixDescription", fixDTO.getFixDescription()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/PatchCommitDTOTest.java b/src/test/java/org/nvip/api/serializers/PatchCommitDTOTest.java new file mode 100644 index 0000000..a49c3ed --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/PatchCommitDTOTest.java @@ -0,0 +1,61 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class PatchCommitDTOTest { + @Test + public void testGettersAndSetters() { + PatchCommitDTO patchCommitDTO = new PatchCommitDTO("old cveid","old name","old commitSha", "old commitMessage","old uniDiff","old timeline","old timeToPatch","old commitDate",0); + patchCommitDTO.setCveId("new cveid"); + patchCommitDTO.setSourceUrl("new SourceUrl"); + patchCommitDTO.setCommitSha("new commitSha"); + patchCommitDTO.setCommitMessage("new commitMessage"); + patchCommitDTO.setUniDiff("new UniDiff"); + patchCommitDTO.setTimeline("new Timeline"); + patchCommitDTO.setTimeToPatch("new timeToPatch"); + patchCommitDTO.setCommitDate("new CommitDate"); + patchCommitDTO.setLinesChanged(1); + + assertEquals("new cveid",patchCommitDTO.getCveId()); + assertEquals("new SourceUrl",patchCommitDTO.getSourceUrl()); + assertEquals("new commitSha",patchCommitDTO.getCommitSha()); + assertEquals("new commitMessage",patchCommitDTO.getCommitMessage()); + assertEquals("new UniDiff",patchCommitDTO.getUniDiff()); + assertEquals("new Timeline",patchCommitDTO.getTimeline()); + assertEquals("new timeToPatch",patchCommitDTO.getTimeToPatch()); + assertEquals("new CommitDate",patchCommitDTO.getCommitDate()); + assertEquals(1,patchCommitDTO.getLinesChanged()); + + + + } + + @Test + public void testBuilder() { + PatchCommitDTO patchCommitDTO = PatchCommitDTO.builder() + .cveId("new cveid") + .sourceUrl("new SourceUrl") + .commitSha("new commitSha") + .commitMessage("new commitMessage") + .uniDiff("new UniDiff") + .timeline("new Timeline") + .timeToPatch("new timeToPatch") + .commitDate("new CommitDate") + .linesChanged(1) + .build(); + + + + assertEquals("new cveid",patchCommitDTO.getCveId()); + assertEquals("new SourceUrl",patchCommitDTO.getSourceUrl()); + assertEquals("new commitSha",patchCommitDTO.getCommitSha()); + assertEquals("new commitMessage",patchCommitDTO.getCommitMessage()); + assertEquals("new UniDiff",patchCommitDTO.getUniDiff()); + assertEquals("new Timeline",patchCommitDTO.getTimeline()); + assertEquals("new timeToPatch",patchCommitDTO.getTimeToPatch()); + assertEquals("new CommitDate",patchCommitDTO.getCommitDate()); + assertEquals(1,patchCommitDTO.getLinesChanged()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/ProductDTOTest.java b/src/test/java/org/nvip/api/serializers/ProductDTOTest.java new file mode 100644 index 0000000..03b6250 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/ProductDTOTest.java @@ -0,0 +1,48 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class ProductDTOTest { + @Test + public void testGettersAndSetters() { + ProductDTO productDTO = new ProductDTO(0,"old productName","old domain","old cpe", "old version", "old purl"); + productDTO.setProductId(1); + productDTO.setProductName("new productName"); + productDTO.setDomain("new domain"); + productDTO.setCpe("new cpe"); + productDTO.setVersion("new version"); + productDTO.setPurl("new purl"); + + + assertEquals(1, productDTO.getProductId()); + assertEquals("new productName", productDTO.getProductName()); + assertEquals("new domain", productDTO.getDomain()); + assertEquals("new cpe", productDTO.getCpe()); + assertEquals("new version", productDTO.getVersion()); + assertEquals("new purl", productDTO.getPurl()); + + + + } + + @Test + public void testBuilder() { + ProductDTO productDTO = ProductDTO.builder() + .productId(1) + .productName("new productName") + .domain("new domain") + .cpe("new cpe") + .version("new version") + .purl("new purl") + .build(); + + assertEquals(1, productDTO.getProductId()); + assertEquals("new productName", productDTO.getProductName()); + assertEquals("new domain", productDTO.getDomain()); + assertEquals("new cpe", productDTO.getCpe()); + assertEquals("new version", productDTO.getVersion()); + assertEquals("new purl", productDTO.getPurl()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/RawDescriptionDTOTest.java b/src/test/java/org/nvip/api/serializers/RawDescriptionDTOTest.java new file mode 100644 index 0000000..1b13368 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/RawDescriptionDTOTest.java @@ -0,0 +1,55 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class RawDescriptionDTOTest { + @Test + public void testGettersAndSetters() { + RawDescriptionDTO rawDescriptionDTO = new RawDescriptionDTO("old cveid","old rawDescription","old createdDate","old publishedDate", "old lastModifiedDate", "old sourceUrl",0,"old sourceType", "old parserType"); + rawDescriptionDTO.setCveId("new cveid"); + rawDescriptionDTO.setRawDescription("new rawDescription"); + rawDescriptionDTO.setCreatedDate("new createdDate"); + rawDescriptionDTO.setPublishedDate("new publishedDate"); + rawDescriptionDTO.setLastModifiedDate("new lastModifiedDate"); + rawDescriptionDTO.setSourceUrl("new sourceUrl"); + rawDescriptionDTO.setIsGarbage(1); + rawDescriptionDTO.setSourceType("new sourceType"); + rawDescriptionDTO.setParserType("new parserType"); + + assertEquals("new cveid",rawDescriptionDTO .getCveId()); + assertEquals("new rawDescription",rawDescriptionDTO .getRawDescription()); + assertEquals("new createdDate",rawDescriptionDTO .getCreatedDate()); + assertEquals("new publishedDate",rawDescriptionDTO .getPublishedDate()); + assertEquals("new lastModifiedDate",rawDescriptionDTO .getLastModifiedDate()); + assertEquals("new sourceUrl",rawDescriptionDTO .getSourceUrl()); + assertEquals(1,rawDescriptionDTO .getIsGarbage()); + assertEquals("new parserType",rawDescriptionDTO .getParserType()); + } + + @Test + public void testBuilder() { + RawDescriptionDTO rawDescriptionDTO = RawDescriptionDTO.builder() + .cveId("new cveid") + .rawDescription("new rawDescription") + .createdDate("new createdDate") + .publishedDate("new publishedDate") + .lastModifiedDate("new lastModifiedDate") + .sourceUrl("new sourceUrl") + .isGarbage(1) + .parserType("new parserType") + .build(); + + + + assertEquals("new cveid",rawDescriptionDTO .getCveId()); + assertEquals("new rawDescription",rawDescriptionDTO .getRawDescription()); + assertEquals("new createdDate",rawDescriptionDTO .getCreatedDate()); + assertEquals("new publishedDate",rawDescriptionDTO .getPublishedDate()); + assertEquals("new lastModifiedDate",rawDescriptionDTO .getLastModifiedDate()); + assertEquals("new sourceUrl",rawDescriptionDTO .getSourceUrl()); + assertEquals(1,rawDescriptionDTO .getIsGarbage()); + assertEquals("new parserType",rawDescriptionDTO .getParserType()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/SSVCDTOTest.java b/src/test/java/org/nvip/api/serializers/SSVCDTOTest.java new file mode 100644 index 0000000..6f4ea94 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/SSVCDTOTest.java @@ -0,0 +1,36 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class SSVCDTOTest { + + SSVCScoreDTO score = new SSVCScoreDTO("low","medium","high"); + SSVCScoreDTO newScore = new SSVCScoreDTO("new low","medium","high"); + @Test + public void testGettersAndSetters() { + SSVCDTO sSVCDTO = new SSVCDTO("old cveid",score,false,"old exploitStatus", false); + sSVCDTO.setCveId("new cveid"); + sSVCDTO.setScores(newScore); + sSVCDTO.setExploitStatus("new exploitStatus"); + + + + assertEquals("new cveid", sSVCDTO.getCveId()); + assertEquals(newScore, sSVCDTO.getScores()); + assertEquals("new exploitStatus", sSVCDTO.getExploitStatus()); + } + + @Test + public void testBuilder() { + SSVCDTO sSVCDTO = SSVCDTO.builder() + .cveId("new cveid") + .scores(newScore) + .exploitStatus("new exploitStatus").build(); + + assertEquals("new cveid", sSVCDTO.getCveId()); + assertEquals(newScore, sSVCDTO.getScores()); + assertEquals("new exploitStatus", sSVCDTO.getExploitStatus()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/SSVCScoreDTOTest.java b/src/test/java/org/nvip/api/serializers/SSVCScoreDTOTest.java new file mode 100644 index 0000000..fe73dc3 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/SSVCScoreDTOTest.java @@ -0,0 +1,47 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +public class SSVCScoreDTOTest { + + @Test + public void testGettersAndSetters() { + SSVCScoreDTO score = new SSVCScoreDTO("old low","old medium","old high"); + score.setScoreLow("new low"); + score.setScoreHigh("new high"); + score.setScoreMedium("new Medium"); + + + + assertEquals("new low", score.getScoreLow()); + assertEquals("new high", score.getScoreHigh()); + assertEquals("new Medium", score.getScoreMedium()); + } + + @Test + public void testBuilder() { + SSVCScoreDTO score = SSVCScoreDTO .builder() + .scoreHigh("new high") + .scoreMedium("new medium") + .scoreLow("new Low").build(); + + assertEquals("new Low", score.getScoreLow()); + assertEquals("new high", score.getScoreHigh()); + assertEquals("new medium", score.getScoreMedium()); + } + + @Test + public void testGet() { + SSVCScoreDTO score = SSVCScoreDTO .builder() + .scoreHigh("new high") + .scoreMedium("new medium") + .scoreLow("new Low").build(); + + assertEquals("new Low", score.get(0)); + assertEquals("new high", score.get(2)); + assertEquals("new medium", score.get(1)); + + } +} diff --git a/src/test/java/org/nvip/api/serializers/UserDTOTest.java b/src/test/java/org/nvip/api/serializers/UserDTOTest.java new file mode 100644 index 0000000..3d460f1 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/UserDTOTest.java @@ -0,0 +1,48 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; + +import static org.junit.Assert.assertEquals; + +public class UserDTOTest { + + LocalDateTime oldtime = LocalDateTime.of(LocalDate.of(Integer.parseInt("2018"), Integer.parseInt("3"), Integer.parseInt("4")), LocalTime.of(Integer.parseInt("3"), Integer.parseInt("3"), Integer.parseInt("4"))); + LocalDateTime newTime = LocalDateTime.of(LocalDate.of(Integer.parseInt("2020"), Integer.parseInt("3"), Integer.parseInt("4")), LocalTime.of(Integer.parseInt("3"), Integer.parseInt("3"), Integer.parseInt("4"))); + @Test + public void testGettersAndSetters() { + UserDTO userDTO = new UserDTO(0,"old token","old userName", 0,oldtime); + userDTO.setUserID(1); + userDTO.setToken("new tokenz"); + userDTO.setUserName("new UserName"); + userDTO.setExpirationDate(newTime); + userDTO.setRoleId(1); + + + + assertEquals(1, userDTO.getUserID()); + assertEquals("new tokenz", userDTO.getToken()); + assertEquals("new UserName" , userDTO.getUserName()); + assertEquals(newTime, userDTO.getExpirationDate()); + assertEquals(1, userDTO.getRoleId()); + } + + @Test + public void testBuilder() { + UserDTO userDTO = UserDTO.builder() + .userID(1) + .token("new token") + .roleId(1) + .expirationDate(newTime) + .userName("new UserName").build(); + + assertEquals(1, userDTO.getUserID()); + assertEquals("new token", userDTO.getToken()); + assertEquals("new UserName" , userDTO.getUserName()); + assertEquals(newTime, userDTO.getExpirationDate()); + assertEquals(1, userDTO.getRoleId()); + } +} diff --git a/src/test/java/org/nvip/api/serializers/VdoCharacteristicDTOTest.java b/src/test/java/org/nvip/api/serializers/VdoCharacteristicDTOTest.java new file mode 100644 index 0000000..9ebb484 --- /dev/null +++ b/src/test/java/org/nvip/api/serializers/VdoCharacteristicDTOTest.java @@ -0,0 +1,50 @@ +package org.nvip.api.serializers; + +import org.junit.jupiter.api.Test; + +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +public class VdoCharacteristicDTOTest { + @Test + public void testGettersAndSetters() { + VdoCharacteristicDTO vdoCharacteristicDTO = new VdoCharacteristicDTO("old cveId","old vdoLabel",0,"old vdoNounGroup", 0, 0); + vdoCharacteristicDTO.setCveId("new cveId"); + vdoCharacteristicDTO.setVdoLabel("new vdoLabel"); + vdoCharacteristicDTO.setVdoConfidence(1); + vdoCharacteristicDTO.setVdoNounGroup("new vdoNounGroup"); + vdoCharacteristicDTO.setUserId(1); + vdoCharacteristicDTO.setIsActive(1); + + assertEquals("new cveId", vdoCharacteristicDTO.getCveId()); + assertEquals("new vdoLabel", vdoCharacteristicDTO.getVdoLabel()); + assertEquals(1, vdoCharacteristicDTO.getVdoConfidence(),0.0003f); + assertEquals("new vdoNounGroup", vdoCharacteristicDTO.getVdoNounGroup()); + assertEquals(Optional.of(1), Optional.of(vdoCharacteristicDTO.getUserId()) ); + assertEquals(1, vdoCharacteristicDTO.getIsActive()); + + + + } + + @Test + public void testBuilder() { + VdoCharacteristicDTO vdoCharacteristicDTO = VdoCharacteristicDTO.builder() + .cveId("new cveId") + .vdoLabel("new vdoLabel") + .vdoConfidence(1) + .vdoNounGroup("new vdoNounGroup") + .userId(1) + .isActive(1) + .build(); + + assertEquals("new cveId", vdoCharacteristicDTO.getCveId()); + assertEquals("new vdoLabel", vdoCharacteristicDTO.getVdoLabel()); + assertEquals(1, vdoCharacteristicDTO.getVdoConfidence(),0.0003f); + assertEquals("new vdoNounGroup", vdoCharacteristicDTO.getVdoNounGroup()); + assertEquals(Optional.of(1), Optional.of(vdoCharacteristicDTO.getUserId()) ); + assertEquals(1, vdoCharacteristicDTO.getIsActive()); + + } +} diff --git a/src/test/java/org/nvip/api/serializers/VulnerabilitySearchParamsTests.java b/src/test/java/org/nvip/api/serializers/VulnerabilitySearchParamsTests.java index d3531da..185e2ba 100644 --- a/src/test/java/org/nvip/api/serializers/VulnerabilitySearchParamsTests.java +++ b/src/test/java/org/nvip/api/serializers/VulnerabilitySearchParamsTests.java @@ -2,6 +2,25 @@ import org.junit.jupiter.api.Test; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + public class VulnerabilitySearchParamsTests { + @Test + public void testGettersAndSetters() { + VulnerabilitySearchParams vulnerabilitySearchParams = new VulnerabilitySearchParams(); + vulnerabilitySearchParams.setCvssScores("cvss;cvss2;cvss3"); + vulnerabilitySearchParams.setVdoLabels(new String[2]); + vulnerabilitySearchParams.setLimitCount(0); + vulnerabilitySearchParams.setProduct("product"); + + + + assertEquals("[cvss, cvss2, cvss3]", Arrays.toString(vulnerabilitySearchParams.getCvssScores())); + assertEquals(new String[2], vulnerabilitySearchParams.getVdoLabels()); + assertEquals(0, vulnerabilitySearchParams.getLimitCount()); + assertEquals("product", vulnerabilitySearchParams.getProduct()); + } } diff --git a/src/test/java/util/TwitterApiTest.java b/src/test/java/util/TwitterApiTest.java index e49e81e..6ec9692 100644 --- a/src/test/java/util/TwitterApiTest.java +++ b/src/test/java/util/TwitterApiTest.java @@ -22,10 +22,11 @@ * SOFTWARE. */ package util; - import static org.junit.Assert.assertEquals; import org.junit.Test; + + import org.nvip.util.TwitterApi;