Skip to content
Permalink
Browse files

feat: allow deleting of Reporters via JSON.

  • Loading branch information...
rhwood committed May 11, 2019
1 parent 874854a commit f91b1a584eb029f400fa59585a3b07d40e8ec9ad
@@ -67,6 +67,11 @@ protected ObjectNode doGet(Reporter reporter, String name, String type, Locale l
return root;
}

@Override
protected void doDelete(Reporter reporter, String name, String type, JsonNode data, Locale locale, int id) throws JsonException {
super.deleteBean(reporter, name, type, data, locale, id);
}

@Override
public JsonNode doSchema(String type, boolean server, Locale locale, int id) throws JsonException {
switch (type) {
@@ -8,11 +8,14 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import jmri.InstanceManager;
import jmri.JmriException;
import jmri.Reporter;
import jmri.ReporterManager;
import jmri.jmrit.operations.locations.Location;
import jmri.jmrit.operations.locations.LocationManager;
import jmri.jmrix.internal.InternalReporterManager;
import jmri.server.json.JSON;
import jmri.server.json.JsonException;
@@ -136,6 +139,40 @@ public Reporter provide(String name) {
}
}

@Test
@Override
public void testDoDelete() throws JsonException {
ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
Reporter reporter1 = manager.provide("IR1");
Location location1 = new Location("1", "Location 1");
location1.setReporter(reporter1);
InstanceManager.getDefault(LocationManager.class).register(location1);
ObjectNode message = mapper.createObjectNode();
// add a reporter
assertNotNull(manager.getReporter("IR1"));
message = mapper.createObjectNode().put(JSON.NAME, "IR1");
try {
service.doDelete(REPORTER, "IR1", NullNode.getInstance(), locale, 0);
fail("Expected exception not thrown");
} catch (JsonException ex) {
assertEquals(409, ex.getCode());
assertEquals(1, ex.getAdditionalData().path(JSON.CONFLICT).size());
assertEquals("Manager", ex.getAdditionalData().path(JSON.CONFLICT).path(0).asText());
message = message.put(JSON.FORCE_DELETE, ex.getAdditionalData().path(JSON.FORCE_DELETE).asText());
}
assertNotNull(manager.getReporter("IR1"));
// will throw if prior catch failed
service.doDelete(REPORTER, "IR1", message, locale, 0);
assertNull(manager.getBeanBySystemName("IR1"));
try {
// deleting again should throw an exception
service.doDelete(REPORTER, "IR1", NullNode.getInstance(), locale, 0);
fail("Expected exception not thrown.");
} catch (JsonException ex) {
assertEquals(404, ex.getCode());
}
}

@Test
public void testDoGetList() throws JsonException {
ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);

0 comments on commit f91b1a5

Please sign in to comment.
You can’t perform that action at this time.