@Test public void prefixDispatchingWithUriNamespaceOwner() throws Throwable { String prefix = UUID.randomUUID().toString(); PrefixDispatchService s = new PrefixDispatchService(); this.host.startServiceAndWait(s, prefix, null); PrefixDispatchService s1 = new PrefixDispatchService(); String longerMatchedPrefix = prefix + "/" + "child"; this.host.startServiceAndWait(s1, longerMatchedPrefix, null); PrefixDispatchService sParent = new PrefixDispatchService(); String prefixMinus = prefix.substring(0, prefix.length() - 3); this.host.startServiceAndWait(sParent, prefixMinus, null); if (!s1.getSelfLink().equals(d.documentSelfLink)) { this.host.failIteration(new IllegalStateException( "Wrong service replied: " + d.documentSelfLink)); Operation put = Operation.createPut(s1.getUri()) .setBody(new ServiceDocument()) .setCompletion(c);
@Test public void prefixDispatchingWithUriNamespaceOwner() throws Throwable { String prefix = UUID.randomUUID().toString(); PrefixDispatchService s = new PrefixDispatchService(); this.host.startServiceAndWait(s, prefix, null); PrefixDispatchService s1 = new PrefixDispatchService(); String longerMatchedPrefix = prefix + "/" + "child"; this.host.startServiceAndWait(s1, longerMatchedPrefix, null); PrefixDispatchService sParent = new PrefixDispatchService(); String prefixMinus = prefix.substring(0, prefix.length() - 3); this.host.startServiceAndWait(sParent, prefixMinus, null); if (!s1.getSelfLink().equals(d.documentSelfLink)) { this.host.failIteration(new IllegalStateException( "Wrong service replied: " + d.documentSelfLink)); Operation put = Operation.createPut(s1.getUri()) .setBody(new ServiceDocument()) .setCompletion(c);
@Override public void handlePost(Operation post) { validateAndComplete(post); }
@Override public void handleOptions(Operation op) { validateAndComplete(op); }
@Override public void handleOptions(Operation op) { validateAndComplete(op); }
@Override public void handleDelete(Operation delete) { validateAndComplete(delete); }
@Override public void handlePost(Operation post) { validateAndComplete(post); }
private void validateAndComplete(Operation op) { if (!op.getUri().getPath().startsWith(getSelfLink())) { op.fail(new IllegalArgumentException("request must start with self link")); return; } op.complete(); }
@Override public void handlePatch(Operation op) { validateAndComplete(op); } }
@Override public void handleDelete(Operation delete) { validateAndComplete(delete); }
@Override public void handlePut(Operation op) { ServiceDocument body = new ServiceDocument(); body.documentSelfLink = getSelfLink(); op.setBody(body); validateAndComplete(op); }
private void verifyDeleteOnNamespaceOwner(PrefixDispatchService s) throws Throwable { // finally, verify we can actually target the service itself, using a DELETE Operation delete = Operation.createDelete(s.getUri()) .setCompletion(this.host.getCompletion()); this.host.testStart(1); this.host.send(delete); this.host.testWait(); assertTrue(this.host.getServiceStage(s.getSelfLink()) == null); }
@Override public void handlePatch(Operation op) { validateAndComplete(op); } }
private void validateAndComplete(Operation op) { if (!op.getUri().getPath().startsWith(getSelfLink())) { op.fail(new IllegalArgumentException("request must start with self link")); return; } op.complete(); }
private void verifyDeleteOnNamespaceOwner(PrefixDispatchService s) throws Throwable { // finally, verify we can actually target the service itself, using a DELETE Operation delete = Operation.createDelete(s.getUri()) .setCompletion(this.host.getCompletion()); this.host.testStart(1); this.host.send(delete); this.host.testWait(); assertTrue(this.host.getServiceStage(s.getSelfLink()) == null); }
@Override public void handlePut(Operation op) { ServiceDocument body = new ServiceDocument(); body.documentSelfLink = getSelfLink(); op.setBody(body); validateAndComplete(op); }