forked from Sage-Bionetworks/sage-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(openchallenges): improve organization service model ImageRespons…
…e and OrganizationMapper unit test coverage (Sage-Bionetworks#2388) * unit test model mapper * update mapper test * add unit tests for null objects entities and dto * unit tests * update tests * update variable names * add comment to document integration test * update the unit tests for mapper * image response test * update unit test * fix variable with method in its place * fix assertion * test * remove mirror org entity * fix assertion * fix assert * update entity variable name * update comment * update variable names * remove comment * update variable names * update variable name * updates to address changes requested * update method calls
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...ebionetworks/openchallenges/organization/service/model/mapper/OrganizationMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.sagebionetworks.openchallenges.organization.service.model.mapper; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.sagebionetworks.openchallenges.organization.service.model.dto.OrganizationDto; | ||
import org.sagebionetworks.openchallenges.organization.service.model.entity.OrganizationEntity; | ||
|
||
public class OrganizationMapperTest { | ||
@Test | ||
public void ConvertToEntity_ShouldReturnDtoProperties_WhenDtoPropertiesPassed() { | ||
|
||
// create new Dto with properties to be copied to organization entity | ||
OrganizationDto dto = new OrganizationDto(); | ||
dto.setName("Test Organization"); | ||
dto.setDescription("This is a test organization"); | ||
dto.setId(4599L); | ||
dto.setEmail("[email protected]"); | ||
dto.setLogin("login"); | ||
dto.setAvatarKey("avatar Key"); | ||
dto.setWebsiteUrl("url"); | ||
dto.setChallengeCount(7); | ||
dto.setAcronym(null); | ||
|
||
OrganizationMapper mapper = new OrganizationMapper(); | ||
|
||
OrganizationEntity entity = mapper.convertToEntity(dto); | ||
|
||
// verify the entity properties were copied | ||
Assertions.assertEquals(entity.getId(), dto.getId()); | ||
Assertions.assertEquals(entity.getName(), dto.getName()); | ||
Assertions.assertEquals(entity.getEmail(), dto.getEmail()); | ||
Assertions.assertEquals(entity.getLogin(), dto.getLogin()); | ||
Assertions.assertEquals(entity.getAvatarKey(), dto.getAvatarKey()); | ||
Assertions.assertEquals(entity.getWebsiteUrl(), dto.getWebsiteUrl()); | ||
Assertions.assertEquals(entity.getChallengeCount(), dto.getChallengeCount()); | ||
Assertions.assertEquals(entity.getDescription(), dto.getDescription()); | ||
Assertions.assertEquals(entity.getAcronym(), dto.getAcronym()); | ||
} | ||
|
||
@Test | ||
public void | ||
ConvertToDto_ShouldReturndDtoWithMatchingEntityProperties_WhenEntityPropertiesPassed() { | ||
|
||
OrganizationEntity entity = new OrganizationEntity(); | ||
|
||
entity.setName("Test Organization"); | ||
entity.setDescription("This is a test organization"); | ||
entity.setId(4599L); | ||
entity.setEmail("[email protected]"); | ||
entity.setLogin("login"); | ||
entity.setAvatarKey("avatar Key"); | ||
entity.setWebsiteUrl("url"); | ||
entity.setChallengeCount(7); | ||
entity.setAcronym(null); | ||
|
||
OrganizationMapper mapper = new OrganizationMapper(); | ||
|
||
OrganizationDto dto = mapper.convertToDto(entity); | ||
|
||
// verify the entity properties were copied | ||
Assertions.assertEquals(entity.getId(), dto.getId()); | ||
Assertions.assertEquals(entity.getName(), dto.getName()); | ||
Assertions.assertEquals(entity.getEmail(), dto.getEmail()); | ||
Assertions.assertEquals(entity.getLogin(), dto.getLogin()); | ||
Assertions.assertEquals(entity.getAvatarKey(), dto.getAvatarKey()); | ||
Assertions.assertEquals(entity.getWebsiteUrl(), dto.getWebsiteUrl()); | ||
Assertions.assertEquals(entity.getChallengeCount(), dto.getChallengeCount()); | ||
Assertions.assertEquals(entity.getDescription(), dto.getDescription()); | ||
Assertions.assertEquals(entity.getAcronym(), dto.getAcronym()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ionetworks/openchallenges/organization/service/model/rest/response/ImageResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.sagebionetworks.openchallenges.organization.service.model.rest.response; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ImageResponseTest { | ||
|
||
@Test | ||
public void ImageUrlGetterAndSetter_ShouldSetAndGetUrl_WhenCalledAfterImageUrlKeyPassed() { | ||
|
||
String imageUrl = "https://example.com/image.jpg"; | ||
ImageResponse imageResponse = new ImageResponse(); | ||
|
||
// Set the url | ||
imageResponse.setUrl(imageUrl); | ||
String actualUrl = imageResponse.getUrl(); | ||
|
||
// Confirm that the same image url was actual that was set | ||
Assertions.assertEquals(imageUrl, actualUrl); | ||
} | ||
} |