package ca.uhn.fhir.jpa.subscription.module;

import ca.uhn.fhir.context.FhirContext;
import org.hl7.fhir.r4.model.Organization;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class ResourceModifiedTest {
	private FhirContext myFhirContext = FhirContext.forR4();

	@Test
	public void testCreate() {
		Organization org = new Organization();
		org.setName("testOrgName");
		org.setId("testOrgId");
		ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, org, ResourceModifiedMessage.OperationTypeEnum.CREATE);
		assertEquals(org.getIdElement(), msg.getId(myFhirContext));
		assertEquals(ResourceModifiedMessage.OperationTypeEnum.CREATE, msg.getOperationType());
		Organization decodedOrg = (Organization) msg.getNewPayload(myFhirContext);
		assertEquals(org.getId(), decodedOrg.getId());
		assertEquals(org.getName(), decodedOrg.getName());
	}

	@Test
	public void testUpdate() {
		Organization org = new Organization();
		org.setName("testOrgName");
		org.setId("testOrgId");
		ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, org, ResourceModifiedMessage.OperationTypeEnum.UPDATE);
		assertEquals(org.getIdElement(), msg.getId(myFhirContext));
		assertEquals(ResourceModifiedMessage.OperationTypeEnum.UPDATE, msg.getOperationType());
		Organization decodedOrg = (Organization) msg.getNewPayload(myFhirContext);
		assertEquals(org.getId(), decodedOrg.getId());
		assertEquals(org.getName(), decodedOrg.getName());
	}

	@Test
	public void testDelete() {
		Organization org = new Organization();
		org.setName("testOrgName");
		org.setId("testOrgId");
		ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, org, ResourceModifiedMessage.OperationTypeEnum.DELETE);
		assertEquals(org.getIdElement(), msg.getId(myFhirContext));
		assertEquals(ResourceModifiedMessage.OperationTypeEnum.DELETE, msg.getOperationType());
		assertNull(msg.getNewPayload(myFhirContext));
	}

}

@@ -441,32 +441,45 @@
 );%0A%09%09org.setId(%22
+Organization/
 testOrgId%22);%0A%09%09R
@@ -1052,32 +1052,45 @@
 );%0A%09%09org.setId(%22
+Organization/
 testOrgId%22);%0A%09%09R

Test fix