private boolean startedDeployedWar(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContextEvent contextEvent = (ApplicationContextEvent) event; if (contextEvent.getApplicationContext() instanceof EmbeddedWebApplicationContext) { EmbeddedWebApplicationContext context = (EmbeddedWebApplicationContext) contextEvent.getApplicationContext(); return context.getEmbeddedServletContainer() == null; } } return false; }
private ResponseEntity<Application> getApp(String id, EmbeddedWebApplicationContext context) { int port = context.getEmbeddedServletContainer().getPort(); ResponseEntity<Application> getResponse = template.getForEntity( "http://localhost:" + port + "/api/applications/" + id, Application.class); return getResponse; }
@Test public void contextLoads() { ResponseEntity<String> entity = restTemplate.getForEntity( "http://localhost:" + server.getEmbeddedServletContainer().getPort() + "/hello", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); }
@SuppressWarnings("unchecked") private ResponseEntity<Collection<Application>> getAppByName( String name, EmbeddedWebApplicationContext context) { int port = context.getEmbeddedServletContainer().getPort(); ResponseEntity<?> getResponse = template.getForEntity( "http://localhost:" + port + "/api/applications?name={name}", ApplicationList.class, Collections.singletonMap("name", name)); return (ResponseEntity<Collection<Application>>) getResponse; }
@After public void shutdown() { instance1.close(); instance2.close(); }
private ResponseEntity<Application> registerApp( Application app, EmbeddedWebApplicationContext context) { int port = context.getEmbeddedServletContainer().getPort(); return template.postForEntity( "http://localhost:" + port + "/api/applications", app, Application.class); }