List of usage examples for java.time Instant now
public static Instant now()
From source file:org.noorganization.instalist.server.api.TagResourceTest.java
@Test public void testPutTag() throws Exception { String url = "/groups/%d/tags/%s"; Instant preUpdate = mTag.getUpdated(); TagInfo updatedList = new TagInfo().withDeleted(false).withName("changedtag"); Response notAuthorizedResponse = target(String.format(url, mGroup.getId(), mTag.getUUID().toString())) .request().put(Entity.json(updatedList)); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId(), mTag.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").put(Entity.json(updatedList)); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId(), mNATag.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(401, wrongGroupResponse.getStatus()); Response wrongListResponse = target(String.format(url, mGroup.getId(), mNATag.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(404, wrongListResponse.getStatus()); Response goneResponse = target(String.format(url, mGroup.getId(), mDeletedTag.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(410, goneResponse.getStatus()); mManager.refresh(mTag);//from w ww .j a v a 2 s.c o m assertEquals("tag1", mTag.getName()); updatedList.setLastChanged(new Date(preUpdate.toEpochMilli() - 10000)); Response conflictResponse = target(String.format(url, mGroup.getId(), mTag.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(409, conflictResponse.getStatus()); mManager.refresh(mTag); assertEquals("tag1", mTag.getName()); updatedList.setLastChanged(Date.from(Instant.now())); Response okResponse = target(String.format(url, mGroup.getId(), mTag.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(200, okResponse.getStatus()); mManager.refresh(mTag); assertEquals("changedtag", mTag.getName()); assertTrue(preUpdate + " is not before " + mTag.getUpdated(), preUpdate.isBefore(mTag.getUpdated())); }
From source file:retsys.client.controller.PurchaseOrderController.java
@Override Object buildRequestMsg() {/*from w ww . java 2s.c om*/ PurchaseOrder po = new PurchaseOrder(); po.setDate(Date.from(Instant.now())); Project projectObj = new Project(); projectObj.setId(splitId(project.getText())); po.setProject(projectObj); po.setDeliveryAddress(delivery_address.getText()); Vendor vendorObj = new Vendor(); vendorObj.setId(splitId(vendor.getText())); po.setVendor(vendorObj); Iterator<POItem> items = poDetail.getItems().iterator(); List<PurchaseOrderDetail> poDetails = new ArrayList<>(); while (items.hasNext()) { POItem poItem = items.next(); PurchaseOrderDetail poDetail = new PurchaseOrderDetail(); Item item = new Item(); item.setId(splitId(poItem.getName().get())); poDetail.setItem(item); poDetail.setQuantity(poItem.getQuantity().get()); poDetail.setConfirm("N"); poDetails.add(poDetail); } po.setPurchaseOrderDetail(poDetails); return po; }
From source file:org.noorganization.instalist.server.api.UnitResourceTest.java
@Test public void testPutUnit() throws Exception { String url = "/groups/%d/units/%s"; Instant preUpdate = mUnit.getUpdated(); UnitInfo updatedList = new UnitInfo().withDeleted(false).withName("changedunit"); Response notAuthorizedResponse = target(String.format(url, mGroup.getId(), mUnit.getUUID().toString())) .request().put(Entity.json(updatedList)); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId(), mUnit.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").put(Entity.json(updatedList)); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId(), mNAUnit.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(401, wrongGroupResponse.getStatus()); Response wrongListResponse = target(String.format(url, mGroup.getId(), mNAUnit.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(404, wrongListResponse.getStatus()); Response goneResponse = target(String.format(url, mGroup.getId(), mDeletedUnit.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(410, goneResponse.getStatus()); mManager.refresh(mUnit);//from ww w.j av a 2 s . c om assertEquals("unit1", mUnit.getName()); updatedList.setLastChanged(new Date(preUpdate.toEpochMilli() - 10000)); Response conflictResponse = target(String.format(url, mGroup.getId(), mUnit.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(409, conflictResponse.getStatus()); mManager.refresh(mUnit); assertEquals("unit1", mUnit.getName()); updatedList.setLastChanged(Date.from(Instant.now())); Response okResponse = target(String.format(url, mGroup.getId(), mUnit.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(200, okResponse.getStatus()); mManager.refresh(mUnit); assertEquals("changedunit", mUnit.getName()); assertTrue(preUpdate + " is not before " + mUnit.getUpdated(), preUpdate.isBefore(mUnit.getUpdated())); }
From source file:com.drunkendev.io.recurse.tests.RecursionTest.java
/** * Times a {@link Runnable} instance.// w w w .jav a 2 s .com * * @param r * {@link Runnable} object to time. * @return {@link Duration} object containing run-time length. */ public Duration time(Runnable r) { Instant start = Instant.now(); r.run(); Duration dur = Duration.between(start, Instant.now()); System.out.format("Completed in: %s%n", dur.toString()); return dur; }
From source file:org.noorganization.instalist.server.api.RecipeResourceTest.java
@Test public void testPutRecipe() throws Exception { String url = "/groups/%d/recipes/%s"; Instant preUpdate = mRecipe.getUpdated(); RecipeInfo updatedList = new RecipeInfo().withDeleted(false).withName("changedrecipe"); Response notAuthorizedResponse = target(String.format(url, mGroup.getId(), mRecipe.getUUID().toString())) .request().put(Entity.json(updatedList)); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId(), mRecipe.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").put(Entity.json(updatedList)); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId(), mNARecipe.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(401, wrongGroupResponse.getStatus()); Response wrongListResponse = target(String.format(url, mGroup.getId(), mNARecipe.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(404, wrongListResponse.getStatus()); Response goneResponse = target(String.format(url, mGroup.getId(), mDeletedRecipe.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(410, goneResponse.getStatus()); mManager.refresh(mRecipe);/*www. j ava 2 s . c o m*/ assertEquals("recipe1", mRecipe.getName()); updatedList.setLastChanged(new Date(preUpdate.toEpochMilli() - 10000)); Response conflictResponse = target(String.format(url, mGroup.getId(), mRecipe.getUUID().toString())) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(409, conflictResponse.getStatus()); mManager.refresh(mRecipe); assertEquals("recipe1", mRecipe.getName()); updatedList.setLastChanged(Date.from(Instant.now())); Response okResponse = target(String.format(url, mGroup.getId(), mRecipe.getUUID().toString())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).put(Entity.json(updatedList)); assertEquals(200, okResponse.getStatus()); mManager.refresh(mRecipe); assertEquals("changedrecipe", mRecipe.getName()); assertTrue(preUpdate + " is not before " + mRecipe.getUpdated(), preUpdate.isBefore(mRecipe.getUpdated())); }
From source file:com.vmware.photon.controller.api.client.resource.FlavorApiTest.java
@Test public void testDelete() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); FlavorApi flavorApi = new FlavorApi(restClient); Task task = flavorApi.delete("foo"); assertEquals(task, responseTask);//from w w w . j a v a 2 s .c om }
From source file:com.joyent.manta.client.multipart.EncryptedJobsMultipartManagerIT.java
public void canAbortMultipartBinary() throws IOException { final long oneMB = 1024L * 1024L; File[] parts = new File[] { createTemporaryDataFile(oneMB, 1), createTemporaryDataFile(oneMB, 1), createTemporaryDataFile(oneMB, 1) }; final String name = uploadName("can-abort-multipart-binary"); final String path = testPathPrefix + name; final EncryptedMultipartUpload<JobsMultipartUpload> upload = multipart.initiateUpload(path); final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>(); for (int i = 0; i < parts.length; i++) { File part = parts[i];//from w w w . j a va2s .c o m int partNumber = i + 1; MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part); uploadedParts.add(uploaded); } multipart.validateThatThereAreSequentialPartNumbers(upload); multipart.complete(upload, uploadedParts); Instant start = Instant.now(); multipart.abort(upload); boolean caught = false; try { multipart.getWrapped().waitForCompletion(upload, (Function<UUID, Void>) uuid -> { fail("Completion operation didn't succeed within timeout"); return null; }); } catch (MantaMultipartException e) { if (e.getMessage().startsWith("Manta job backing multipart upload was " + "aborted. This upload was unable to be completed.")) { caught = true; } } assertTrue(caught, "Backing job aborted exception wasn't thrown"); Instant end = Instant.now(); MantaMultipartStatus status = multipart.getStatus(upload); assertEquals(status, MantaMultipartStatus.ABORTED); MantaJob job = multipart.getWrapped().findJob(upload); Duration totalCompletionTime = Duration.between(start, end); LOG.info("Aborting took {} seconds", totalCompletionTime.toMillis() / 1000); if (!job.getCancelled()) { fail("Job wasn't cancelled:" + job.toString()); } assertFalse(mantaClient.existsAndIsAccessible(multipart.getWrapped().multipartUploadDir(upload.getId())), "Upload directory shouldn't be present after abort"); }
From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java
@Test public void testDelete() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); FlavorApi flavorApi = new FlavorRestApi(restClient); Task task = flavorApi.delete("foo"); assertEquals(task, responseTask);//from www.ja va2s . co m }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformStartOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performStartOperationAsync("foo", new FutureCallback<Task>() { @Override/* w w w . j a va 2 s . co m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformStartOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performStartOperationAsync("foo", new FutureCallback<Task>() { @Override//w ww . j a va2 s . c o m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }