WebCommandDispatcher { public Object handle(HttpServletRequest httpReq, ModelEvent<String> event) { Command cmd = getBuilder().build(httpReq, event); return handle(cmd, event.getPayload()); } WebCommandDispatcher(BeanResolverStrategy beanResolver); Object handle(HttpServletRequest httpReq, ModelEvent<String> event); Object handle(HttpServletRequest httpReq, String json); MultiOutput handle(Command cmd, String payload);  }
@Test public void testHandleViaEventPayload() { final MockHttpServletRequest request = new MockHttpServletRequest(); final ModelEvent<String> event = new ModelEvent<>(); event.setPayload("{}"); final String commandUri = "/Acme/abc/def/p/home/_new&execute"; final Command expectedCommand = CommandBuilder.withUri(commandUri).getCommand(); final MultiOutput expected = new MultiOutput(commandUri, new ExecutionContext(expectedCommand), Action._new, Behavior.$execute); Mockito.when(this.builder.build(request, event)).thenReturn(expectedCommand); Mockito.when(this.gateway.execute(expectedCommand, event.getPayload())).thenReturn(expected); final Object actual = this.testee.handle(request, event); Mockito.verify(this.builder, Mockito.only()).build(request, event); Mockito.verify(this.gateway, Mockito.times(1)).execute(expectedCommand, event.getPayload()); Assert.assertEquals(expected, actual); }
@Test public void testHandleViaJsonAndBuildCommand() { final MockHttpServletRequest request = new MockHttpServletRequest(); final String payload = "{}"; final String commandUri = "/Acme/abc/def/p/home/_new&execute"; final Command expectedCommand = CommandBuilder.withUri(commandUri).getCommand(); final MultiOutput expected = new MultiOutput(commandUri, new ExecutionContext(expectedCommand), Action._new, Behavior.$execute); Mockito.when(this.builder.build(request)).thenReturn(expectedCommand); Mockito.when(this.gateway.execute(expectedCommand, payload)).thenReturn(expected); final Object actual = this.testee.handle(request, payload); Mockito.verify(this.builder, Mockito.only()).build(request); Mockito.verify(this.gateway, Mockito.times(1)).execute(expectedCommand, payload); Assert.assertEquals(expected, actual); }
@Test public void testHandleViaJsonAndProvidedCommand() { final String payload = "{}"; final String commandUri = "/Acme/abc/def/p/home/_new&execute"; final Command command = CommandBuilder.withUri(commandUri).getCommand(); final MultiOutput expected = new MultiOutput(commandUri, new ExecutionContext(command), Action._new, Behavior.$execute); Mockito.when(this.gateway.execute(command, payload)).thenReturn(expected); final Object actual = this.testee.handle(command, payload); Mockito.verify(this.gateway, Mockito.times(1)).execute(command, payload); Assert.assertEquals(expected, actual); }