<commit_before>package gov.nih.nci.cabig.caaers.service.migrator;

import edu.nwu.bioinformatics.commons.ResourceRetriever;
import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.domain.ConfigPropertyType;
import gov.nih.nci.cabig.caaers.domain.report.ReportDefinition;

import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

/*
* @author <NAME>
* */
public class ReportDefinitionConverterTest extends CaaersDbTestCase{
	
	ReportDefinitionConverter reportDefinitionConverter;
	private JAXBContext jaxbContext = null;
	private Unmarshaller unmarshaller = null;
	private gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions reportDefinitions = null;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.reportdefinition");
		unmarshaller = jaxbContext.createUnmarshaller();
		reportDefinitionConverter = (ReportDefinitionConverter)getDeployedApplicationContext().getBean("reportDefinitionConverter");
	}
	
	public void testdtoToDomain() throws Exception {
		
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/ctep_24_hour_sae_notification.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		
		assertNotNull(reportDefinitionDomain);
		assertEquals("TEST CTEP 24 Hour SAE Notification", reportDefinitionDomain.getName());
		assertNotNull(reportDefinitionDomain.getGroup());
		assertEquals("RT_INST", reportDefinitionDomain.getGroup().getCode());
		assertEquals(reportDefinitionDto.getDeliveryDefinition().size(), reportDefinitionDomain.getDeliveryDefinitions().size());
		assertEquals(reportDefinitionDto.getMandatoryField().size(), reportDefinitionDomain.getMandatoryFields().size());
		assertEquals(reportDefinitionDto.getPlannedNotificaiton().size(), reportDefinitionDomain.getPlannedNotifications().size());
		
		
	}
    
    /*
    * @author <NAME>
    * Testing whether the importing procedure is working for the reports definitions marked as Custom Report Format Type
    *
    * */
	public void testCustomDtoToDomain() throws Exception {
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/custom-report.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		assertEquals("CUSTOM_REPORT", reportDefinitionDomain.getReportFormatType().getCode());
	}

	public void testdomainToDto() throws Exception {
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/ctep_24_hour_sae_notification.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		assertNotNull(reportDefinitionDomain);
		assertEquals("TEST CTEP 24 Hour SAE Notification", reportDefinitionDomain.getName());
		assertNotNull(reportDefinitionDomain.getGroup());
		assertEquals("RT_INST", reportDefinitionDomain.getGroup().getCode());
		assertNotNull(reportDefinitionDomain.getGroup().getConfigType());
		assertEquals(ConfigPropertyType.REPORT_GROUP, reportDefinitionDomain.getGroup().getConfigType());
		
		reportDefinitions = reportDefinitionConverter.domainToDto(reportDefinitionDomain);<commit_msg>CAAERS-3730<commit_after>package gov.nih.nci.cabig.caaers.service.migrator;

import edu.nwu.bioinformatics.commons.ResourceRetriever;
import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.domain.ConfigPropertyType;
import gov.nih.nci.cabig.caaers.domain.ReportFormatType;
import gov.nih.nci.cabig.caaers.domain.report.ReportDefinition;

import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

/*
* @author <NAME>
* */
public class ReportDefinitionConverterTest extends CaaersDbTestCase{
	
	ReportDefinitionConverter reportDefinitionConverter;
	private JAXBContext jaxbContext = null;
	private Unmarshaller unmarshaller = null;
	private gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions reportDefinitions = null;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.reportdefinition");
		unmarshaller = jaxbContext.createUnmarshaller();
		reportDefinitionConverter = (ReportDefinitionConverter)getDeployedApplicationContext().getBean("reportDefinitionConverter");
	}
	
	public void testdtoToDomain() throws Exception {
		
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/ctep_24_hour_sae_notification.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		
		assertNotNull(reportDefinitionDomain);
		assertEquals("TEST CTEP 24 Hour SAE Notification", reportDefinitionDomain.getName());
		assertNotNull(reportDefinitionDomain.getGroup());
		assertEquals("RT_INST", reportDefinitionDomain.getGroup().getCode());
		assertEquals(reportDefinitionDto.getDeliveryDefinition().size(), reportDefinitionDomain.getDeliveryDefinitions().size());
		assertEquals(reportDefinitionDto.getMandatoryField().size(), reportDefinitionDomain.getMandatoryFields().size());
		assertEquals(reportDefinitionDto.getPlannedNotificaiton().size(), reportDefinitionDomain.getPlannedNotifications().size());
		
		
	}
    
    /*
    * @author <NAME>
    * Testing whether the importing procedure is working for the reports definitions marked as Custom Report Format Type
    *
    * */
	public void testCustomDtoToDomain() throws Exception {
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/custom-report.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		assertEquals(ReportFormatType.CUSTOM_REPORT, reportDefinitionDomain.getReportFormatType().getCode());
	}

	public void testdomainToDto() throws Exception {
		reportDefinitions = (gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitions) unmarshaller.unmarshal(createInputStream("testdata/ctep_24_hour_sae_notification.xml"));
		gov.nih.nci.cabig.caaers.reportdefinition.ReportDefinitionType reportDefinitionDto = reportDefinitions.getReportDefinition().get(0);
		ReportDefinition reportDefinitionDomain = reportDefinitionConverter.dtoToDomain(reportDefinitionDto);
		assertNotNull(reportDefinitionDomain);
		assertEquals("TEST CTEP 24 Hour SAE Notification", reportDefinitionDomain.getName());
		assertNotNull(reportDefinitionDomain.getGroup());
		assertEquals("RT_INST", reportDefinitionDomain.getGroup().getCode());
		assertNotNull(reportDefinitionDomain.getGroup().getConfigType());
		assertEquals(ConfigPropertyType.REPORT_GROUP, reportDefinitionDomain.getGroup().getConfigType());
		
		reportDefinitions = reportDefinitionConverter.domainToDto(reportDefinitionDomain);
{'fraction_non_alphanumeric': 0.10050825921219822, 'fraction_numerical': 0.003303684879288437, 'mean_word_length': 7.85376827896513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1470348', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2175, 'n_words': 297}