Fix interceptor behaviour
This commit is contained in:
parent
d87b4f2062
commit
b2996d3550
|
@ -209,9 +209,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
if (next instanceof IJpaServerInterceptor) {
|
||||||
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
||||||
}
|
}
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
}
|
||||||
((IServerOperationInterceptor) next).resourceDeleted(theRequestDetails, resourceToDelete);
|
}
|
||||||
}
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
((IServerOperationInterceptor) next).resourceDeleted(theRequestDetails, resourceToDelete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,11 +280,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
if (next instanceof IJpaServerInterceptor) {
|
||||||
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
((IServerOperationInterceptor) next).resourceDeleted(theRequestDetails, resourceToDelete);
|
((IServerOperationInterceptor) next).resourceDeleted(theRequestDetails, resourceToDelete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IBaseOperationOutcome oo;
|
IBaseOperationOutcome oo;
|
||||||
|
@ -392,9 +395,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
if (next instanceof IJpaServerInterceptor) {
|
||||||
((IJpaServerInterceptor) next).resourceCreated(requestDetails, entity);
|
((IJpaServerInterceptor) next).resourceCreated(requestDetails, entity);
|
||||||
}
|
}
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
}
|
||||||
((IServerOperationInterceptor) next).resourceCreated(theRequestDetails, theResource);
|
}
|
||||||
}
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
((IServerOperationInterceptor) next).resourceCreated(theRequestDetails, theResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1136,12 +1141,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
if (next instanceof IJpaServerInterceptor) {
|
||||||
((IJpaServerInterceptor) next).resourceUpdated(requestDetails, entity);
|
((IJpaServerInterceptor) next).resourceUpdated(requestDetails, entity);
|
||||||
}
|
}
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
|
||||||
((IServerOperationInterceptor) next).resourceDeleted(theRequestDetails, theResource);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
((IServerOperationInterceptor) next).resourceUpdated(theRequestDetails, theResource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
||||||
|
|
||||||
if (!thePerformIndexing) {
|
if (!thePerformIndexing) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3InterceptorTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3InterceptorTest.class);
|
||||||
private IJpaServerInterceptor myJpaInterceptor;
|
private IJpaServerInterceptor myJpaInterceptor;
|
||||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
||||||
|
private IServerOperationInterceptor myServerOperationInterceptor;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void after() {
|
public void after() {
|
||||||
|
@ -59,8 +61,20 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
||||||
|
|
||||||
|
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock theInvocation) throws Throwable {
|
||||||
|
if (theInvocation.getMethod().getReturnType().equals(boolean.class)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
myDaoConfig.getInterceptors().add(myJpaInterceptor);
|
myDaoConfig.getInterceptors().add(myJpaInterceptor);
|
||||||
myDaoConfig.getInterceptors().add(myJpaInterceptorAdapter);
|
myDaoConfig.getInterceptors().add(myJpaInterceptorAdapter);
|
||||||
|
myDaoConfig.getInterceptors().add(myServerOperationInterceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -200,6 +214,52 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
verifyNoMoreInteractions(myRequestOperationCallback);
|
verifyNoMoreInteractions(myRequestOperationCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testServerOperationCreate() {
|
||||||
|
verify(myServerOperationInterceptor, times(0)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().setFamily("PATIENT");
|
||||||
|
IIdType id = myPatientDao.create(p, (RequestDetails)null).getId();
|
||||||
|
assertEquals(1L, id.getVersionIdPartAsLong().longValue());
|
||||||
|
|
||||||
|
verify(myServerOperationInterceptor, times(1)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testServerOperationUpdate() {
|
||||||
|
verify(myServerOperationInterceptor, times(0)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
verify(myServerOperationInterceptor, times(0)).resourceUpdated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().setFamily("PATIENT");
|
||||||
|
IIdType id = myPatientDao.create(p, (RequestDetails)null).getId();
|
||||||
|
assertEquals(1L, id.getVersionIdPartAsLong().longValue());
|
||||||
|
|
||||||
|
p.addName().setFamily("2");
|
||||||
|
myPatientDao.update(p);
|
||||||
|
|
||||||
|
verify(myServerOperationInterceptor, times(1)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
verify(myServerOperationInterceptor, times(1)).resourceUpdated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testServerOperationDelete() {
|
||||||
|
verify(myServerOperationInterceptor, times(0)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
verify(myServerOperationInterceptor, times(0)).resourceDeleted(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().setFamily("PATIENT");
|
||||||
|
IIdType id = myPatientDao.create(p, (RequestDetails)null).getId();
|
||||||
|
assertEquals(1L, id.getVersionIdPartAsLong().longValue());
|
||||||
|
|
||||||
|
p.addName().setFamily("2");
|
||||||
|
myPatientDao.delete(p.getIdElement().toUnqualifiedVersionless());
|
||||||
|
|
||||||
|
verify(myServerOperationInterceptor, times(1)).resourceCreated(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
verify(myServerOperationInterceptor, times(1)).resourceDeleted(Mockito.isNull(RequestDetails.class), any(IBaseResource.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestOperationDelete() {
|
public void testRequestOperationDelete() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
|
Loading…
Reference in New Issue