Search in sources :

Example 1 with AffectedParty

use of ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty in project moh-hnweb by bcgov.

the class AuditServiceTest method testCreateAffectedParty.

@Test
public void testCreateAffectedParty() {
    Transaction transaction = auditService.createTransaction("0:0:0:0:0:0:0:1", TransactionType.CHECK_ELIGIBILITY);
    AffectedParty newAffectedParty = auditService.createAffectedParty(transaction, IdentifierType.GROUP_NUMBER, "6337109");
    Optional<AffectedParty> optional = affectedPartyRepository.findById(newAffectedParty.getAffectedPartyId());
    assertTrue(optional.isPresent());
    AffectedParty affectedParty = optional.get();
    assertNotNull(affectedParty.getAffectedPartyId());
    assertEquals("6337109", affectedParty.getIdentifier());
    assertEquals(IdentifierType.GROUP_NUMBER.getValue(), affectedParty.getIdentifierType());
    assertEquals(transaction, affectedParty.getTransaction());
}
Also used : AffectedParty(ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty) Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AffectedParty

use of ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty in project moh-hnweb by bcgov.

the class EligibilityControllerTest method testLookupPhn_success.

@Test
public void testLookupPhn_success() {
    mockBackEnd.enqueue(new MockResponse().setBody(R42_SUCCESS).addHeader(CONTENT_TYPE, MediaType.TEXT_PLAIN.toString()));
    LookupPhnRequest lookupPhnRequest = new LookupPhnRequest();
    lookupPhnRequest.setContractNumber("123456789");
    lookupPhnRequest.setGroupNumber("1234567");
    ResponseEntity<LookupPhnResponse> response = eligibilityController.lookupPhn(lookupPhnRequest, createHttpServletRequest());
    LookupPhnResponse lookupPhnResponse = response.getBody();
    // Check the response
    assertEquals(StatusEnum.SUCCESS, lookupPhnResponse.getStatus());
    assertEquals("TRANSACTION SUCCESSFUL", lookupPhnResponse.getMessage());
    // Check the client request is sent as expected
    List<LookupPhnBeneficiary> beneficiaries = lookupPhnResponse.getBeneficiaries();
    assertEquals(1, beneficiaries.size());
    LookupPhnBeneficiary beneficiary = beneficiaries.get(0);
    assertEquals("9123456789", beneficiary.getPhn());
    assertEquals("CHECKSETSNAME", beneficiary.getLastName());
    assertEquals("CHECSETFNAME", beneficiary.getFirstName());
    assertEquals("CHESERSNDNAME", beneficiary.getSecondName());
    assertEquals("19700101", beneficiary.getDateOfBirth());
    assertEquals("M", beneficiary.getGender());
    // The request should produce:
    // - Transaction
    // - 'Transaction Start' TransactionEvent
    // - 2 x Request AffectedParty
    // - 'Message Sent' TransactionEvent
    // - 'Message Received' TransactionEvent
    // - 'Transaction Complete' TransactionEvent
    // - 1 x Response AffectedParty
    Transaction transaction = assertTransactionCreated(TransactionType.PHN_LOOKUP);
    assertEquals("00000010", transaction.getOrganization());
    assertNotNull(transaction.getServer());
    assertNotNull(transaction.getSessionId());
    assertEquals("1.1.1.1", transaction.getSourceIp());
    assertNotNull(transaction.getStartTime());
    assertNotNull(transaction.getTransactionId());
    assertEquals(TransactionType.PHN_LOOKUP.getValue(), transaction.getType());
    assertEquals("unittest", transaction.getUserId());
    List<TransactionEvent> transactionEvents = transactionEventRepository.findAll(Sort.by("eventTime"));
    assertEquals(4, transactionEvents.size());
    TransactionEvent transactionStartEvent = transactionEvents.get(0);
    assertNotNull(transactionStartEvent.getEventTime());
    assertNull(transactionStartEvent.getMessageId());
    assertEquals(transaction, transactionStartEvent.getTransaction());
    assertNotNull(transactionStartEvent.getTransactionEventId());
    assertEquals(TransactionEventType.TRANSACTION_START.getValue(), transactionStartEvent.getType());
    TransactionEvent messageSentEvent = transactionEvents.get(1);
    assertNotNull(messageSentEvent.getEventTime());
    assertNull(messageSentEvent.getMessageId());
    assertEquals(transaction, messageSentEvent.getTransaction());
    assertNotNull(messageSentEvent.getTransactionEventId());
    assertEquals(TransactionEventType.MESSAGE_SENT.getValue(), messageSentEvent.getType());
    TransactionEvent messageReceivedEvent = transactionEvents.get(2);
    assertNotNull(messageReceivedEvent.getEventTime());
    assertNull(messageReceivedEvent.getMessageId());
    assertEquals(transaction, messageReceivedEvent.getTransaction());
    assertNotNull(messageReceivedEvent.getTransactionEventId());
    assertEquals(TransactionEventType.MESSAGE_RECEIVED.getValue(), messageReceivedEvent.getType());
    TransactionEvent transactionCompleteEvent = transactionEvents.get(3);
    assertNotNull(transactionCompleteEvent.getEventTime());
    assertNull(transactionCompleteEvent.getMessageId());
    assertEquals(transaction, transactionCompleteEvent.getTransaction());
    assertNotNull(transactionCompleteEvent.getTransactionEventId());
    assertEquals(TransactionEventType.TRANSACTION_COMPLETE.getValue(), transactionCompleteEvent.getType());
    List<AffectedParty> affectedParties = affectedPartyRepository.findAll(Sort.by("identifierType"));
    assertEquals(3, affectedParties.size());
    AffectedParty contractNumber = affectedParties.get(0);
    assertNotNull(contractNumber.getAffectedPartyId());
    assertEquals("123456789", contractNumber.getIdentifier());
    assertEquals(IdentifierType.CONTRACT_NUMBER.getValue(), contractNumber.getIdentifierType());
    assertEquals(transaction, contractNumber.getTransaction());
    AffectedParty groupNumber = affectedParties.get(1);
    assertNotNull(groupNumber.getAffectedPartyId());
    assertEquals("1234567", groupNumber.getIdentifier());
    assertEquals(IdentifierType.GROUP_NUMBER.getValue(), groupNumber.getIdentifierType());
    assertEquals(transaction, groupNumber.getTransaction());
    AffectedParty phn = affectedParties.get(2);
    assertNotNull(phn.getAffectedPartyId());
    assertEquals("9123456789", phn.getIdentifier());
    assertEquals(IdentifierType.PHN.getValue(), phn.getIdentifierType());
    assertEquals(transaction, phn.getTransaction());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) AffectedParty(ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty) TransactionEvent(ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent) LookupPhnRequest(ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnRequest) Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) LookupPhnBeneficiary(ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnBeneficiary) LookupPhnResponse(ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnResponse) BaseControllerTest(ca.bc.gov.hlth.hnweb.BaseControllerTest) Test(org.junit.jupiter.api.Test)

Example 3 with AffectedParty

use of ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty in project moh-hnweb by bcgov.

the class AuditService method createAffectedParty.

/**
 * Creates a new {@link AffectedParty}.
 *
 * @param transaction The associated Transaction
 * @param identifierType The type of identifier
 * @param identifier The value of the identifier
 */
public AffectedParty createAffectedParty(Transaction transaction, IdentifierType identifierType, String identifier) {
    AffectedParty affectedParty = new AffectedParty();
    affectedParty.setIdentifier(identifier);
    affectedParty.setIdentifierType(identifierType.getValue());
    affectedParty.setTransaction(transaction);
    return affectedPartyRepository.save(affectedParty);
}
Also used : AffectedParty(ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty)

Aggregations

AffectedParty (ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty)3 Transaction (ca.bc.gov.hlth.hnweb.persistence.entity.Transaction)2 Test (org.junit.jupiter.api.Test)2 BaseControllerTest (ca.bc.gov.hlth.hnweb.BaseControllerTest)1 LookupPhnBeneficiary (ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnBeneficiary)1 LookupPhnRequest (ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnRequest)1 LookupPhnResponse (ca.bc.gov.hlth.hnweb.model.rest.eligibility.LookupPhnResponse)1 TransactionEvent (ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1