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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations