Search in sources :

Example 1 with TransactionEvent

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

the class BaseController method transactionError.

/**
 * Audits an Error event.
 *
 * @param transaction The transaction
 * @param status The HTTP status code
 * @param exception The exception
 */
private void transactionError(Transaction transaction, HttpStatus status, Exception exception) {
    TransactionEvent transactionEvent = auditService.createTransactionEvent(transaction, TransactionEventType.ERROR);
    auditService.createEventMessage(transactionEvent, ErrorLevel.ERROR, status, exception);
}
Also used : TransactionEvent(ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent)

Example 2 with TransactionEvent

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

the class AuditServiceTest method testCreateEventMessage.

@Test
public void testCreateEventMessage() {
    HNWebException exception = new HNWebException(ExceptionType.DOWNSTREAM_FAILURE);
    Transaction transaction = auditService.createTransaction("0:0:0:0:0:0:0:1", TransactionType.CHECK_ELIGIBILITY);
    TransactionEvent transactionEvent = auditService.createTransactionEvent(transaction, TransactionEventType.TRANSACTION_START, UUID.randomUUID().toString());
    EventMessage newEventMessage = auditService.createEventMessage(transactionEvent, ErrorLevel.ERROR, HttpStatus.INTERNAL_SERVER_ERROR, exception);
    Optional<EventMessage> optional = eventMessageRepository.findById(newEventMessage.getEventMessageId());
    assertTrue(optional.isPresent());
    EventMessage eventMessage = optional.get();
    assertEquals(Integer.toString(HttpStatus.INTERNAL_SERVER_ERROR.value()), eventMessage.getErrorCode());
    assertEquals(ErrorLevel.ERROR, eventMessage.getErrorLevel());
    assertNotNull(eventMessage.getEventMessageId());
    assertEquals(ExceptionType.DOWNSTREAM_FAILURE.getMessage(), eventMessage.getMessageText());
    assertEquals(transactionEvent, eventMessage.getTransactionEvent());
}
Also used : TransactionEvent(ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent) HNWebException(ca.bc.gov.hlth.hnweb.exception.HNWebException) Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) EventMessage(ca.bc.gov.hlth.hnweb.persistence.entity.EventMessage) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TransactionEvent

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

the class AuditServiceTest method testCreateTransactionEvent.

@Test
public void testCreateTransactionEvent() {
    String messageId = StringUtils.substring(UUID.randomUUID().toString(), 0, 20);
    Transaction transaction = auditService.createTransaction("0:0:0:0:0:0:0:1", TransactionType.CHECK_ELIGIBILITY);
    TransactionEvent newTransactionEvent = auditService.createTransactionEvent(transaction, TransactionEventType.TRANSACTION_START, messageId);
    Optional<TransactionEvent> optional = transactionEventRepository.findById(newTransactionEvent.getTransactionEventId());
    assertTrue(optional.isPresent());
    TransactionEvent transactionEvent = optional.get();
    assertNotNull(transactionEvent.getEventTime());
    assertEquals(messageId, transactionEvent.getMessageId());
    assertEquals(transaction, transactionEvent.getTransaction());
    assertNotNull(transactionEvent.getTransactionEventId());
    assertEquals(TransactionEventType.TRANSACTION_START.getValue(), transactionEvent.getType());
}
Also used : TransactionEvent(ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent) Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with TransactionEvent

use of ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent 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 5 with TransactionEvent

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

the class AuditService method createTransactionEvent.

/**
 * Creates a new {@link TransactionEvent}.
 *
 * @param transaction The associated Transaction
 * @param eventType The type of event
 * @param messageId The associated message ID
 * @return The persisted TransactionEvent.
 */
public TransactionEvent createTransactionEvent(Transaction transaction, TransactionEventType eventType, String messageId) {
    TransactionEvent transactionEvent = new TransactionEvent();
    transactionEvent.setEventTime(new Date());
    transactionEvent.setMessageId(messageId);
    transactionEvent.setTransaction(transaction);
    transactionEvent.setType(eventType.getValue());
    return transactionEventRepository.save(transactionEvent);
}
Also used : TransactionEvent(ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent) Date(java.util.Date)

Aggregations

TransactionEvent (ca.bc.gov.hlth.hnweb.persistence.entity.TransactionEvent)5 Transaction (ca.bc.gov.hlth.hnweb.persistence.entity.Transaction)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BaseControllerTest (ca.bc.gov.hlth.hnweb.BaseControllerTest)1 HNWebException (ca.bc.gov.hlth.hnweb.exception.HNWebException)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 AffectedParty (ca.bc.gov.hlth.hnweb.persistence.entity.AffectedParty)1 EventMessage (ca.bc.gov.hlth.hnweb.persistence.entity.EventMessage)1 Date (java.util.Date)1 MockResponse (okhttp3.mockwebserver.MockResponse)1