LocalApplicationsResource implements RootResource, SynchronousResource, BlockingResource { @Override public String id() { return "applications"; } LocalApplicationsResource(InternalApplicationRegistry applicationRegistry, File applicationsDirectory); void parent(Resource parent); @Override Resource parent(); @Override String id(); @Override void createMember(RequestContext ctx, ResourceState state, Responder responder); @Override void readMember(RequestContext ctx, String id, Responder responder); @Override void updateProperties(RequestContext ctx, ResourceState state, Responder responder); @Override void delete(RequestContext ctx, Responder responder);  }
@Test public void localAppImportTests() throws Exception { HttpPost postRequest; CloseableHttpResponse response; postRequest = new HttpPost("http: postRequest.setEntity(new StringEntity("{ \"id\": \"myapp\", \"name\": \"My Application\" }")); postRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(postRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(406); response.close(); postRequest = new HttpPost("http: postRequest.setEntity(new StringEntity("{ \"id\": \"myapp\", \"name\": \"My Application\", \"localPath\": \"\" }")); postRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(postRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(406); response.close(); postRequest = new HttpPost("http: postRequest.setEntity(new StringEntity("{ \"id\": \"myapp\", \"name\": \"My Application\", \"localPath\": \"myDodgyPath\" }")); postRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(postRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(406); response.close(); String badAppPath = new File(getClass().getClassLoader().getResource("importApps/badApp").getFile()).getAbsolutePath(); badAppPath = badAppPath.replace("\\", "\\\\"); postRequest = new HttpPost("http: postRequest.setEntity(new StringEntity("{ \"id\": \"badapp\", \"name\": \"Bad Application\", \"localPath\": \"" + badAppPath + "\" }")); postRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(postRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(406); response.close(); CompletableFuture<StompMessage> appCreationNotification = new CompletableFuture<>(); StompClient stompClient = new StompClient(); CountDownLatch subscriptionLatch = new CountDownLatch(1); stompClient.connect("localhost", 8080, (client) -> { stompClient.subscribe("/admin/applications/*", (subscription) -> { subscription.onMessage((msg) -> { System.err.println("******* MESSAGE: " + msg); if (msg.headers().get("location").equals("/admin/applications/myapp")) { appCreationNotification.complete(msg); } }); subscription.onReceipt(() -> { subscriptionLatch.countDown(); }); }); }); subscriptionLatch.await(); HttpGet getRequest; String appPath = new File(getClass().getClassLoader().getResource("importApps/app1").getFile()).getAbsolutePath(); appPath = appPath.replace("\\", "\\\\"); postRequest = new HttpPost("http: postRequest.setEntity(new StringEntity("{ \"id\": \"myapp\", \"localPath\": \"" + appPath + "\" }")); postRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(postRequest); awaitStability(); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(201); ResourceState state = decode(response); assertThat(state).isNotNull(); assertThat(state).isInstanceOf(ResourceState.class); assertThat(state.id()).isNotNull(); assertThat(state.id()).isEqualTo("myapp"); assertThat(state.getProperty(LiveOak.NAME)).isEqualTo("app1"); assertThat(state.getProperty("visible")).isEqualTo(true); StompMessage obj = appCreationNotification.get(30, TimeUnit.SECONDS); assertThat(obj).isNotNull(); ResourceState appObjState = decode(obj.content()); assertThat(appObjState.getProperty(LiveOak.NAME)).isEqualTo("app1"); assertThat(state.getProperty(LiveOak.ID)).isEqualTo(appObjState.getProperty(LiveOak.ID)); response.close(); getRequest = new HttpGet("http: getRequest.setHeader("Content-Type", MediaType.JSON.toString()); response = this.httpClient.execute(getRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); state = decode(response); assertThat(state).isNotNull(); assertThat(state.members().size()).isEqualTo(3); response.close(); assertThat(system.vertx().fileSystem().existsSync(appDir.getPath() + "/myapp/app/index.html")).isTrue(); File myApp = new File(appDir, "myapp"); assertThat(new File(myApp, ".git").exists()).isTrue(); Git git = Git.open(myApp); assertThat(git.status().call().hasUncommittedChanges()).isFalse(); Iterable<RevCommit> commits = git.log().call(); int count = 0; for (RevCommit rev : commits) { count++; } assertThat(count).isEqualTo(1); getRequest = new HttpGet("http: getRequest.setHeader("Accept", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(getRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(405); response.close(); HttpPut putRequest = new HttpPut("http: putRequest.setHeader("Content-Type", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(putRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(405); response.close(); HttpDelete deleteRequest = new HttpDelete("http: getRequest.setHeader("Accept", MediaType.LOCAL_APP_JSON.toString()); response = httpClient.execute(deleteRequest); assertThat(response).isNotNull(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(405); response.close(); }