Skip to content

Serializers tests #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/test/java/org/nvip/api/serializers/CvssDTOTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
33 changes: 33 additions & 0 deletions src/test/java/org/nvip/api/serializers/DescriptionDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
62 changes: 62 additions & 0 deletions src/test/java/org/nvip/api/serializers/ExploitDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
31 changes: 31 additions & 0 deletions src/test/java/org/nvip/api/serializers/FixDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
61 changes: 61 additions & 0 deletions src/test/java/org/nvip/api/serializers/PatchCommitDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
48 changes: 48 additions & 0 deletions src/test/java/org/nvip/api/serializers/ProductDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
55 changes: 55 additions & 0 deletions src/test/java/org/nvip/api/serializers/RawDescriptionDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
36 changes: 36 additions & 0 deletions src/test/java/org/nvip/api/serializers/SSVCDTOTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading