try {
processPolicy(data, ident);
+ if (data.isUnchanged()) {
+ throw new PfModelException(Status.BAD_REQUEST, "policy does not appear in any PDP group: "
+ + ident.getName() + " " + ident.getVersion());
+ }
+
} catch (PfModelException | RuntimeException e) {
// no need to log the error object here, as it will be logged by the invoker
logger.warn("failed to undeploy policy: {}", ident);
pdpRequests.compute(change.getName(), (name, data) -> Pair.of((data == null ? null : data.getLeft()), change));
}
+ /**
+ * Determines if any changes were made due to the REST call.
+ *
+ * @return {@code true} if nothing was changed, {@code false} if something was changed
+ */
+ public boolean isUnchanged() {
+ return pdpRequests.isEmpty();
+ }
+
/**
* Gets the accumulated PDP requests.
*
@Test
public void testDeleteGroup_NotFound() throws Exception {
assertThatThrownBy(() -> prov.deleteGroup(GROUP1_NAME)).isInstanceOf(PfModelException.class)
- .hasMessage("group not found").matches(thr -> {
- PfModelException ex = (PfModelException) thr;
- return (ex.getErrorResponse().getResponseCode() == Status.NOT_FOUND);
- });
+ .hasMessage("group not found")
+ .extracting(ex -> ((PfModelException) ex).getErrorResponse().getResponseCode())
+ .isEqualTo(Status.NOT_FOUND);
}
@Test
}
@Test
- public void testUndeploy_testDeletePolicy() throws Exception {
+ public void testUndeploy_testUndeployPolicy() throws Exception {
prov.undeploy(optIdent);
}
}
@Test
- public void testDeletePolicy_DaoEx() throws Exception {
+ public void testUndeployPolicy_NotFound() throws Exception {
+ when(session.isUnchanged()).thenReturn(true);
+
+ assertThatThrownBy(() -> prov.undeploy(optIdent)).isInstanceOf(PfModelException.class)
+ .hasMessage("policy does not appear in any PDP group: policyA null");
+ }
+
+ @Test
+ public void testUndeployPolicy_DaoEx() throws Exception {
PfModelException exc = new PfModelException(Status.BAD_REQUEST, EXPECTED_EXCEPTION);
prov = spy(prov);
}
@Test
- public void testDeletePolicy_RtEx() throws Exception {
+ public void testUndeployPolicy_RtEx() throws Exception {
RuntimeException exc = new RuntimeException(EXPECTED_EXCEPTION);
prov = spy(prov);
when(dao.getFilteredPolicyList(any())).thenReturn(Collections.emptyList());
assertThatThrownBy(() -> prov.process(loadRequest(), this::handle)).isInstanceOf(PfModelRuntimeException.class)
- .hasMessage("cannot find policy: policyA 1.2.3").matches(thr -> {
- PfModelRuntimeException exc = (PfModelRuntimeException) thr;
- return (exc.getErrorResponse().getResponseCode() == Status.NOT_FOUND);
- });
+ .hasMessage("cannot find policy: policyA 1.2.3")
+ .extracting(ex -> ((PfModelRuntimeException) ex).getErrorResponse().getResponseCode())
+ .isEqualTo(Status.NOT_FOUND);
}
@Test
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
}
@Test
- public void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() {
+ public void testIsUnchanged_testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() {
+ assertTrue(session.isUnchanged());
+
// pre-load with a update and state-change for other PDPs
PdpUpdate update2 = makeUpdate(PDP2);
session.addUpdate(update2);
PdpUpdate update = makeUpdate(PDP1);
PdpStateChange change = makeStateChange(PDP1);
session.addRequests(update, change);
+ assertFalse(session.isUnchanged());
verifyRequests(update, update2, change, change3);
/*
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
+ assertEquals("policy does not appear in any PDP group: onap.restart.tcaB null", resp.getErrorDetails());
}
@Test
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
+ assertEquals("policy does not appear in any PDP group: onap.restart.tcaC 1.0.0", resp.getErrorDetails());
}
}