Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

This is one of my converter class, package com.sc.we.idv.model.converter; import…

  1. User

    This is one of my converter class, package com.sc.we.idv.model.converter;

    import java.nio.charset.Charset; import java.sql.Timestamp;

    import org.springframework.stereotype.Component;

    import com.sc.we.idv.common.model.BiometricVerificationResponse; import com.sc.we.idv.entity.EkycGoldenSourcePayload; import com.sc.we.idv.entity.IDVEkycGoldenSource;

    import static com.sc.we.idv.common.constants.IDVConstants.*;

    @Component public class BiometricResponseToEntityConverter {

    public IDVEkycGoldenSource bioMetricToGoldenSourceExtracted(BiometricVerificationResponse res,
    		EkycGoldenSourcePayload ekycGoldenSourcePayload, String idNumber) {
    	IDVEkycGoldenSource iDVEkycGoldenSource = new IDVEkycGoldenSource();
    
    	iDVEkycGoldenSource.setIdvEkycGoldenSourcePayloadId(ekycGoldenSourcePayload.getId());
    	iDVEkycGoldenSource.setCreatedDate(new Timestamp(System.currentTimeMillis()));
    	iDVEkycGoldenSource.setAckReferenceNo(res.getServiceInfo().getAckReference());
    	iDVEkycGoldenSource.setTransactionReferenceNo(res.getServiceInfo().getTransactionReference());
    
    	iDVEkycGoldenSource.setChannelReference(res.getServiceInfo().getChannelReference());
    	if (null != res.getResponseInfo().getProcessStatus()
    			&& res.getResponseInfo().getProcessStatus().equalsIgnoreCase("100")) {
    		iDVEkycGoldenSource.setResultCode(SCCUESS_CODE);
    		iDVEkycGoldenSource.setResultMessage(res.getResponseInfo().getProcessDescription());
    	}
    	iDVEkycGoldenSource.setDocumentNumber(idNumber);
    	return iDVEkycGoldenSource;
    }
    
    public EkycGoldenSourcePayload bioMetricResponseToGoldenSourcePayload(BiometricVerificationResponse response) {
    	EkycGoldenSourcePayload idvEkycGoldenSourcePayload = new EkycGoldenSourcePayload();
    	idvEkycGoldenSourcePayload.setTransactionReference(response.getServiceInfo().getTransactionReference());
    	idvEkycGoldenSourcePayload.setAckReferenceNo(response.getServiceInfo().getAckReference());
    	idvEkycGoldenSourcePayload.setChannelReference(response.getServiceInfo().getChannelReference());
    	idvEkycGoldenSourcePayload.setFingerprintMatchGoldenSourceData(getResponseBytes(response));
    	idvEkycGoldenSourcePayload.setCreatedDate(getCurrentTime());
    	return idvEkycGoldenSourcePayload;
    }
    
    private byte[] getResponseBytes(BiometricVerificationResponse response) {
    	return (null != response) ? response.toString().getBytes(Charset.forName("UTF-8")) : null;
    	
    }
    
    private Timestamp getCurrentTime() {
    	return new Timestamp(System.currentTimeMillis());
    }
    

    }

    This is its test class, package com.sc.we.idv.model.converter;

    import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;

    import org.junit.jupiter.api.Test; import org.mockito.InjectMocks;

    import com.sc.we.idv.TestCVUtils; import com.sc.we.idv.TestCommonUtils; import com.sc.we.idv.common.model.BiometricVerificationRequest; import com.sc.we.idv.common.model.BiometricVerificationResponse; import com.sc.we.idv.entity.EkycGoldenSourcePayload; import com.sc.we.idv.entity.IDVEkycGoldenSource; import com.sc.we.idv.exceptions.UnexpectedErrorExcpetion;

    public class BiometricResponseToEntityConverterTest {

    @InjectMocks
    private BiometricResponseToEntityConverter converter = new BiometricResponseToEntityConverter();
    
    @Test
    public void testBioMetricIDVBOToGoldenSourceExtractedConvertor() {
    	// Given
    	BiometricVerificationResponse res = TestCommonUtils.buildBiometricVerificationResponse();
    	res.getServiceInfo().setAckReference("IDV-PK-01-20241118213041-4b1168c1-6fa7-4662-8");
    	res.getServiceInfo().setTransactionReference("PKNREF1002312323129");
    	res.getServiceInfo().setChannelReference("PK20240423001");
    	Long id = (long) 1;
    	EkycGoldenSourcePayload ekyc = new EkycGoldenSourcePayload();
    	ekyc.setId(id);
    	
    	// When
    	IDVEkycGoldenSource goldenSourceExtracted = converter.bioMetricToGoldenSourceExtracted(res, ekyc, "12312345");
    
    	// Then
    	assertNotNull(goldenSourceExtracted);
    	assertEquals(goldenSourceExtracted.getDocumentNumber(), "12312345");
    }
    
    
    @Test
    public void testBioMetricResponseToGoldenSourcePayloadConverter() throws UnexpectedErrorExcpetion {
    	// Given
    	BiometricVerificationResponse response = TestCommonUtils.buildBiometricVerificationResponse();
    	response.setResponseInfo(TestCommonUtils.buildResponseInfoBioMetric());
    
    	// When
    	EkycGoldenSourcePayload goldenSourcePayload = converter.bioMetricResponseToGoldenSourcePayload(response);
    
    	// Then
    	assertNotNull(goldenSourcePayload);
    	assertEquals(goldenSourcePayload.getTransactionReference(), response.getServiceInfo().getTransactionReference());
    	
    }
    

    }

    Similarly this is a new converter class, package com.sc.we.idv.faceCapture.model.convertor;

    import com.sc.we.idv.faceCapture.model.InitializeResponse; import com.sc.we.idv.faceCapture.model.InternalInfo; import com.sc.we.idv.faceCapture.model.ServiceInfo; import com.sc.we.idv.model.IDVTransactionBO; import org.springframework.stereotype.Component;

    @Component public class IDVTransactionBOToInitializeResponse { public InitializeResponse convert(IDVTransactionBO transactionBO) { InitializeResponse response = new InitializeResponse(); response.serviceInfo(buildServiceInfo(transactionBO)); response.setInternalInfo(buildInternalInfo(transactionBO)); return response; }

    private InternalInfo buildInternalInfo(IDVTransactionBO transactionBO) {
        InternalInfo internalInfo = new InternalInfo();
        internalInfo.setServiceType(transactionBO.getServiceType());
        internalInfo.setSourceCountry(transactionBO.getSourceCountry());
        internalInfo.setSystemIdentifier(transactionBO.getSystemIdentifier());
        return internalInfo;
    }
    
    private ServiceInfo buildServiceInfo(IDVTransactionBO transactionBO) {
        ServiceInfo serviceInfo = new ServiceInfo();
        serviceInfo.setTransactionReference(transactionBO.getTransactionReference());
        serviceInfo.setChannelReference(transactionBO.getChannelReference());
        serviceInfo.setAckReference(transactionBO.getAckReferenceNo());
        serviceInfo.setVendorTransactionId(transactionBO.getVendorTransactionId());
        serviceInfo.setSegmentCode(transactionBO.getSegmentCode());
        serviceInfo.setProductIdentifier(transactionBO.getProductIdentifier());
        return serviceInfo;
    }
    

    }

    Finish this test class for this class, package com.sc.we.idv.faceCapture.model.converter;

    import com.sc.we.idv.TestCommonUtils; import com.sc.we.idv.common.model.BiometricVerificationResponse; import com.sc.we.idv.entity.EkycGoldenSourcePayload; import com.sc.we.idv.entity.IDVEkycGoldenSource; import com.sc.we.idv.faceCapture.model.convertor.IDVTransactionBOToInitializeResponse; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks;

    import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;

    public class IDVTransactionBOToInitializeResponseTest {

    @InjectMocks
    IDVTransactionBOToInitializeResponse conveter = new IDVTransactionBOToInitializeResponse();
    

    }

  2. Assistant

    Here’s the completed test class for the IDVTransactionBOToInitializeResponse converter. This class includes unit tests to verify that the conversion from IDVTransactionBO to InitializeResponse is performed correctly.

    package com.sc.we.idv.faceCapture.model.converter;
    
    import com.sc.we.idv.TestCommonUtils; // This import assumes you have utility methods to create test instances
    import com.sc.we.idv.faceCapture.model.InitializeResponse;
    import com.sc.we.idv.faceCapture.model.InternalInfo;
    import com.sc.we.idv.faceCapture.model.ServiceInfo;
    import com.sc.we.idv.model.IDVTransactionBO;
    import org.junit.jupiter.api.Test;
    import org.mockito.InjectMocks;
    
    import static org.junit.jupiter.api.Assertions.assertEquals;
    import static org.junit.jupiter.api.Assertions.assertNotNull;
    
    public class IDVTransactionBOToInitializeResponseTest {
        
        @InjectMocks
        IDVTransactionBOToInitializeResponse converter = new IDVTransactionBOToInitializeResponse();
    
        @Test
        public void testConvert() {
            // Given
            IDVTransactionBO transactionBO = TestCommonUtils.buildIDVTransactionBO(); // Assumes this method creates a valid IDVTransactionBO
    
            // When
            InitializeResponse response = converter.convert(transactionBO);
    
            // Then
            assertNotNull(response);
            assertNotNull(response.getServiceInfo());
            assertNotNull(response.getInternalInfo());
    
            // Assertions to verify service info
            ServiceInfo serviceInfo = response.getServiceInfo();
            assertEquals(transactionBO.getTransactionReference(), serviceInfo.getTransactionReference());
            assertEquals(transactionBO.getChannelReference(), serviceInfo.getChannelReference());
            assertEquals(transactionBO.getAckReferenceNo(), serviceInfo.getAckReference());
            assertEquals(transactionBO.getVendorTransactionId(), serviceInfo.getVendorTransactionId());
            assertEquals(transactionBO.getSegmentCode(), serviceInfo.getSegmentCode());
            assertEquals(transactionBO.getProductIdentifier(), serviceInfo.getProductIdentifier());
    
            // Assertions to verify internal info
            InternalInfo internalInfo = response.getInternalInfo();
            assertEquals(transactionBO.getServiceType(), internalInfo.getServiceType());
            assertEquals(transactionBO.getSourceCountry(), internalInfo.getSourceCountry());
            assertEquals(transactionBO.getSystemIdentifier(), internalInfo.getSystemIdentifier());
        }
    }
    

    Key Points:

    1. Test Setup: The test class uses @InjectMocks to inject the IDVTransactionBOToInitializeResponse converter instance, which makes testing easier.

    2. Test Method: The testConvert() method creates a test instance of IDVTransactionBO (defined in your test utility class) and calls the convert method of the converter.

    3. Assertions: Various assertions are performed to ensure that the converted InitializeResponse object contains expected values. You need to ensure that TestCommonUtils.buildIDVTransactionBO() provides a well-defined instance for the conversion test.

    4. Null Checks: Before making assertions on the properties of the converted object, null checks are conducted to confirm that the object and its properties are properly initialized.

    This structure provides a solid foundation for testing the IDVTransactionBOToInitializeResponse converter. Adjust the TestCommonUtils as necessary to generate valid test data for IDVTransactionBO.

  3. User

    This is my another converter class, package com.sc.we.idv.faceCapture.model.convertor;

    import com.sc.we.idv.common.enums.IDVTransactionStatus; import com.sc.we.idv.faceCapture.entity.IDVFaceCaptureTransaction; import com.sc.we.idv.model.IDVTransactionBO; import org.springframework.stereotype.Component;

    import java.sql.Timestamp;

    @Component public class IDVTransactionBOToIDVFaceCaptureTxn { public IDVFaceCaptureTransaction convert(IDVTransactionBO transactionBO) { IDVFaceCaptureTransaction idvFaceCaptureTransaction = new IDVFaceCaptureTransaction(); idvFaceCaptureTransaction.setTxnReferenceNo(transactionBO.getTransactionReference()); idvFaceCaptureTransaction.setChannelReference(transactionBO.getChannelReference()); idvFaceCaptureTransaction.setAckReferenceNo(transactionBO.getAckReferenceNo()); idvFaceCaptureTransaction.setVendorTransactionId(transactionBO.getVendorTransactionId()); idvFaceCaptureTransaction.setSourceCountry(transactionBO.getSourceCountry()); idvFaceCaptureTransaction.setCreatedDate(new Timestamp(System.currentTimeMillis())); idvFaceCaptureTransaction.setCurrentState(IDVTransactionStatus.INITIALIZED.name()); return idvFaceCaptureTransaction; } }

    Finish this test class also, package com.sc.we.idv.faceCapture.model.converter;

    public class IDVTransactionBOToIDVFaceCaptureTxnTest { }

  4. Assistant

    Here’s the completed test class for the IDVTransactionBOToIDVFaceCaptureTxn converter. This test validates the conversion from IDVTransactionBO to IDVFaceCaptureTransaction.

    package com.sc.we.idv.faceCapture.model.converter;
    
    import com.sc.we.idv.TestCommonUtils; // Assuming this provides utility methods to create test instances
    import com.sc.we.idv.faceCapture.entity.IDVFaceCaptureTransaction;
    import com.sc.we.idv.model.IDVTransactionBO;
    import org.junit.jupiter.api.Test;
    import org.mockito.InjectMocks;
    
    import java.sql.Timestamp;
    
    import static org.junit.jupiter.api.Assertions.assertEquals;
    import static org.junit.jupiter.api.Assertions.assertNotNull;
    
    public class IDVTransactionBOToIDVFaceCaptureTxnTest {
    
        @InjectMocks
        IDVTransactionBOToIDVFaceCaptureTxn converter = new IDVTransactionBOToIDVFaceCaptureTxn();
    
        @Test
        public void testConvert() {
            // Given
            IDVTransactionBO transactionBO = TestCommonUtils.buildIDVTransactionBO(); // Assumes this method creates a valid IDVTransactionBO 
    
            // When
            IDVFaceCaptureTransaction faceCaptureTransaction = converter.convert(transactionBO);
    
            // Then
            assertNotNull(faceCaptureTransaction);
            // Verifying properties of IDVFaceCaptureTransaction
            assertEquals(transactionBO.getTransactionReference(), faceCaptureTransaction.getTxnReferenceNo());
            assertEquals(transactionBO.getChannelReference(), faceCaptureTransaction.getChannelReference());
            assertEquals(transactionBO.getAckReferenceNo(), faceCaptureTransaction.getAckReferenceNo());
            assertEquals(transactionBO.getVendorTransactionId(), faceCaptureTransaction.getVendorTransactionId());
            assertEquals(transactionBO.getSourceCountry(), faceCaptureTransaction.getSourceCountry());
            
            // You can also validate the createdDate and the currentState
            assertNotNull(faceCaptureTransaction.getCreatedDate());
            assertEquals(IDVTransactionStatus.INITIALIZED.name(), faceCaptureTransaction.getCurrentState());
        }
    }
    

    Explanation and Key Points:

    1. Test Class: The test class is named IDVTransactionBOToIDVFaceCaptureTxnTest and includes the necessary imports.

    2. Test Injection: An instance of IDVTransactionBOToIDVFaceCaptureTxn is created using the @InjectMocks annotation. This allows you to test the conversion logic directly.

    3. Setup Test Data: The TestCommonUtils.buildIDVTransactionBO() method is assumed to return a valid instance of IDVTransactionBO that can be used for testing.

    4. Conversion Test: The testConvert() method performs the conversion from IDVTransactionBO to IDVFaceCaptureTransaction.

    5. Assertions:

      • The test checks that the returned IDVFaceCaptureTransaction object is not null.
      • It verifies that all relevant fields in the IDVFaceCaptureTransaction object match those in the provided IDVTransactionBO instance.
      • It confirms that the creation date is not null and that the current state matches the expected status of INITIALIZED.

    Adjustments:

    • Ensure that the utility method TestCommonUtils.buildIDVTransactionBO() is defined and returns an object populated with valid test data.
    • You may want to add more tests for edge cases or exceptional conditions based on how your application is expected to behave.