Skip to content

Commit

Permalink
test(openchallenges): improve organization service model ImageRespons…
Browse files Browse the repository at this point in the history
…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
mdsage1 authored Dec 8, 2023
1 parent cd30508 commit ca0f467
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
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());
}
}
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);
}
}

0 comments on commit ca0f467

Please sign in to comment.