Skip to content

Commit

Permalink
Tests: Add template autoselection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinFutterer authored and rekt-hard committed Mar 11, 2024
1 parent f070647 commit 5a3b6c7
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package at.ac.tuwien.damap.conversion;

import at.ac.tuwien.damap.TestSetup;
import at.ac.tuwien.damap.enums.ETemplateType;
import at.ac.tuwien.damap.rest.dmp.domain.DmpDO;
import at.ac.tuwien.damap.rest.dmp.domain.FundingDO;
import at.ac.tuwien.damap.rest.dmp.domain.ProjectDO;
import at.ac.tuwien.damap.util.MockDmpService;
import at.ac.tuwien.damap.util.TestDOFactory;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.security.TestSecurity;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

@QuarkusTest
class TemplateSelectorServiceImplTest extends TestSetup {

@Inject
TestDOFactory testDOFactory;

@Inject
MockDmpService dmpService;

@Inject
TemplateSelectorServiceImpl templateSelectorService;

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasUnknownFunding_whenTemplateIsSelected_thenShouldReturnScienceEurope() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456UnknwonFunder");
project.setDescription("Test unknown funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100004955");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.SCIENCE_EUROPE, templateSelectorService.selectTemplate(updatedDMP));
}

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasFWFFunding_whenTemplateIsSelected_thenShouldReturnFWF() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456FWFFunder");
project.setDescription("Test FWF funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100002428");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.FWF, templateSelectorService.selectTemplate(updatedDMP));
}

@Test
@TestSecurity(authorizationEnabled = false)
void givenDmpHasUnknownFunding_whenTemplateIsSelected_thenShouldReturnHorizonEurope() {
DmpDO testDMP = testDOFactory.createDmp(this.toString(), true);

ProjectDO project = testDMP.getProject();
project.setUniversityId("123456HEFunder");
project.setDescription("Test HE funder.");
FundingDO fundingDO = project.getFunding();
fundingDO.getFunderId().setIdentifier("501100000780");
project.setFunding(fundingDO);

testDMP.setProject(project);
DmpDO updatedDMP = dmpService.update(testDMP);

Assertions.assertEquals(ETemplateType.HORIZON_EUROPE, templateSelectorService.selectTemplate(updatedDMP));
}
}

0 comments on commit 5a3b6c7

Please sign in to comment.