List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformStartOperation() 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); VmApi vmApi = new VmRestApi(restClient); Task task = vmApi.performStartOperation("foo"); assertEquals(task, responseTask);/* ww w .java 2 s . c o m*/ }
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 av a 2 s . com 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:org.codice.ddf.catalog.ui.query.monitor.impl.WorkspaceQueryService.java
private Date getOneDayBack() { return Date.from(Instant.now().minus(1, ChronoUnit.DAYS)); }
From source file:retsys.client.controller.PurchaseOrderController.java
@Override Object buildRequestMsg() {//from w w w .j a v a 2s. co m 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.jboss.pnc.mavenrepositorymanager.MavenRepositorySession.java
/** * Promote all build dependencies NOT ALREADY CAPTURED to the hosted repository holding store for the shared imports and * return dependency artifacts meta data. * * @param report The tracking report that contains info about artifacts downloaded by the build * @return List of dependency artifacts meta data * @throws RepositoryManagerException In case of a client API transport error or an error during promotion of artifacts */// w ww. j a v a2 s . c o m private List<Artifact> processDownloads(TrackedContentDTO report) throws RepositoryManagerException { Logger logger = LoggerFactory.getLogger(getClass()); IndyContentClientModule content; try { content = indy.content(); } catch (IndyClientException e) { throw new RepositoryManagerException("Failed to retrieve AProx client module. Reason: %s", e, e.getMessage()); } List<Artifact> deps = new ArrayList<>(); Set<TrackedContentEntryDTO> downloads = report.getDownloads(); if (downloads != null) { Map<StoreKey, Set<String>> toPromote = new HashMap<>(); StoreKey sharedImports = new StoreKey(StoreType.hosted, MavenRepositoryConstants.SHARED_IMPORTS_ID); // StoreKey sharedReleases = new StoreKey(StoreType.hosted, RepositoryManagerDriver.SHARED_RELEASES_ID); for (TrackedContentEntryDTO download : downloads) { String path = download.getPath(); if (ignoreContent(path)) { logger.debug("Ignoring download (matched in ignored-suffixes): {} (From: {})", download.getPath(), download.getStoreKey()); continue; } StoreKey sk = download.getStoreKey(); // If the entry is from a hosted repository, it shouldn't be auto-promoted. // If the entry is already in shared-imports, it shouldn't be auto-promoted to there. // New binary imports will be coming from a remote repository... // TODO: Enterprise maven repository (product repo) handling... if (isExternalOrigin(sk) && StoreType.hosted != sk.getType()) { switch (download.getAccessChannel()) { case MAVEN_REPO: // this has not been captured, so promote it. Set<String> paths = toPromote.get(sk); if (paths == null) { paths = new HashSet<>(); toPromote.put(sk, paths); } paths.add(download.getPath()); break; default: // do not promote anything else anywhere break; } } ArtifactPathInfo pathInfo = ArtifactPathInfo.parse(path); String identifier; if (pathInfo == null) { identifier = download.getOriginUrl(); if (identifier == null) { // this is from a hosted repository, either shared-imports or a build, or something like that. identifier = download.getLocalUrl(); } identifier += '|' + download.getSha256(); } else { ArtifactRef aref = new SimpleArtifactRef(pathInfo.getProjectId(), pathInfo.getType(), pathInfo.getClassifier()); identifier = aref.toString(); } logger.info("Recording download: {}", identifier); String originUrl = download.getOriginUrl(); if (originUrl == null) { // this is from a hosted repository, either shared-imports or a build, or something like that. originUrl = download.getLocalUrl(); } Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(download.getMd5()) .sha1(download.getSha1()).sha256(download.getSha256()).size(download.getSize()) .deployPath(download.getPath()).originUrl(originUrl).importDate(Date.from(Instant.now())) .filename(new File(path).getName()).identifier(identifier) .repoType(toRepoType(download.getAccessChannel())); Artifact artifact = validateArtifact(artifactBuilder.build()); deps.add(artifact); } for (Map.Entry<StoreKey, Set<String>> entry : toPromote.entrySet()) { PathsPromoteRequest req = new PathsPromoteRequest(entry.getKey(), sharedImports, entry.getValue()) .setPurgeSource(false); doPromoteByPath(req); } } return deps; }
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 w w w .j a v a 2s . c o m*/ 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:alfio.manager.AdminReservationManager.java
private Result<Boolean> performUpdate(String reservationId, Event event, TicketReservation r, AdminReservationModification arm) { ticketReservationRepository.updateValidity(reservationId, Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant())); if (arm.isUpdateContactData()) { AdminReservationModification.CustomerData customerData = arm.getCustomerData(); ticketReservationRepository.updateTicketReservation(reservationId, r.getStatus().name(), customerData.getEmailAddress(), customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), customerData.getUserLanguage(), customerData.getBillingAddress(), r.getConfirmationTimestamp(), Optional.ofNullable(r.getPaymentMethod()).map(PaymentProxy::name).orElse(null)); }// w w w. ja v a 2s .c om arm.getTicketsInfo().stream().filter(TicketsInfo::isUpdateAttendees) .flatMap(ti -> ti.getAttendees().stream()) .forEach(a -> ticketRepository.updateTicketOwnerById(a.getTicketId(), trimToNull(a.getEmailAddress()), trimToNull(a.getFullName()), trimToNull(a.getFirstName()), trimToNull(a.getLastName()))); return Result.success(true); }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.TestElasticsearchHadoopUtils.java
@Test public void test_getTimedIndexes() { final LinkedHashMultimap<String, String> test_in = LinkedHashMultimap.create(); test_in.put("test_time_sliced_index__4633d78cd58b_2015.04.01", "test"); test_in.put("test_time_sliced_index__4633d78cd58b_2015.06.01", "test"); test_in.put("r__test_time_sliced_index__4633d78cd58b_2015.06.03", "test"); test_in.put("r__test_time_sliced_index__4633d78cd58b", "test"); // min + max//from www . j av a 2 s . c om { final Date now = Date .from(LocalDateTime.of(2015, 6, 12, 2, 0).atZone(ZoneOffset.systemDefault()).toInstant()); AnalyticThreadJobInputConfigBean test = BeanTemplateUtils.build(AnalyticThreadJobInputConfigBean.class) .with(AnalyticThreadJobInputConfigBean::time_min, "12 days") .with(AnalyticThreadJobInputConfigBean::time_max, "8 days").done().get(); AnalyticThreadJobInputBean input = BeanTemplateUtils.build(AnalyticThreadJobInputBean.class) .with(AnalyticThreadJobInputBean::config, test).done().get(); final Optional<Stream<String>> res = ElasticsearchHadoopUtils.getTimedIndexes(input, test_in, now); assertEquals( Arrays.asList("test_time_sliced_index__4633d78cd58b_2015.06.01", "r__test_time_sliced_index__4633d78cd58b_2015.06.03"), res.map(s -> s.collect(Collectors.toList())).get()); } // neither { AnalyticThreadJobInputConfigBean test = BeanTemplateUtils.build(AnalyticThreadJobInputConfigBean.class) .done().get(); AnalyticThreadJobInputBean input = BeanTemplateUtils.build(AnalyticThreadJobInputBean.class) .with(AnalyticThreadJobInputBean::config, test).done().get(); final Optional<Stream<String>> res = ElasticsearchHadoopUtils.getTimedIndexes(input, test_in, new Date()); assertEquals(Optional.empty(), res); } }
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);/* w w w. j av a2 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 ww .ja v a 2 s . c om }