List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogService.java
public Optional<Role> getRole(String roleName) { List<QueryParam> qps = QueryParam.params(Role.NAME, String.valueOf(roleName)); Collection<Role> roles = listRoles(qps); return roles.isEmpty() ? Optional.empty() : Optional.of(roles.iterator().next()); }
From source file:com.devicehive.defects.Defect157CommandTest.java
@Before public void prepareCommands() { DeviceClassEquipmentVO equipment = DeviceFixture.createEquipmentVO(); DeviceClassUpdate deviceClass = DeviceFixture.createDeviceClass(); deviceClass.setEquipment(Optional.of(Collections.singleton(equipment))); NetworkVO network = DeviceFixture.createNetwork(); DeviceUpdate deviceUpdate = DeviceFixture.createDevice(guid); deviceUpdate.setDeviceClass(Optional.of(deviceClass)); deviceUpdate.setNetwork(Optional.of(network)); // register device Response response = performRequest("/device/" + guid, "PUT", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), deviceUpdate, NO_CONTENT, null);/*from w ww.ja va2s . c om*/ assertNotNull(response); { DeviceCommand command = createDeviceCommand("c1", "s2"); command = performRequest("/device/" + guid + "/command", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), command, CREATED, DeviceCommand.class); assertNotNull(command.getId()); } { DeviceCommand command = createDeviceCommand("c2", "s1"); command = performRequest("/device/" + guid + "/command", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), command, CREATED, DeviceCommand.class); assertNotNull(command.getId()); } { DeviceCommand command = createDeviceCommand("c3", "s3"); command = performRequest("/device/" + guid + "/command", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), command, CREATED, DeviceCommand.class); assertNotNull(command.getId()); } }
From source file:tds.assessment.web.endpoints.ItemControllerTest.java
@Test public void itShouldReturnItemMetadataForItem() { ItemFileMetadata itemFileMetadata = ItemFileMetadata.create(ItemFileType.ITEM, "test", "test", "test"); when(mockItemService.findItemFileMetadataByItemKey("SBAC_PT", 1, 4)) .thenReturn(Optional.of(itemFileMetadata)); ResponseEntity<ItemFileMetadata> response = itemController.findItemFileMetadata("SBAC_PT", 1, null, 4L); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isEqualTo(itemFileMetadata); }
From source file:com.ethercamp.harmony.service.PeersService.java
@PostConstruct private void postConstruct() { // gather blocks to calculate hash rate ethereum.addListener(new EthereumListenerAdapter() { @Override//from ww w .j av a 2 s . co m public void onRecvMessage(Channel channel, Message message) { // notify client about new block // using PeerDTO as it already has both country fields if (message.getCommand() == EthMessageCodes.NEW_BLOCK) { clientMessageService.sendToTopic("/topic/newBlockFrom", createPeerDTO(channel.getPeerId(), channel.getInetSocketAddress().getHostName(), 0l, 0.0, 0, true, null, Optional.of(channel.getEthHandler().getBestKnownBlock()) .map(b -> b.getNumber()).orElse(0L))); } } }); createGeoDatabase(); }
From source file:com.arpnetworking.metrics.portal.hosts.impl.ElasticSearchHostRegistryTest.java
@Test public void testAddHost() throws InterruptedException { final Host expectedHost = addOrUpdateHost("testAddHost-host1", MetricsSoftwareState.LATEST_VERSION_INSTALLED, null); // Indexing is asynchronous at an interval of 1 second (see @Before) Thread.sleep(2000);/*from w w w . ja va2 s .c om*/ final QueryResult<Host> result = _repository.createQuery() .partialHostname(Optional.of(expectedHost.getHostname())).execute(); final Host actualHost = Iterables.getFirst(result.values(), null); Assert.assertEquals(expectedHost, actualHost); Assert.assertEquals(1, result.total()); }
From source file:tech.beshu.ror.integration.JwtAuthTests.java
@Test public void rejectTokentWithUserClaimAndCustomHeader() throws Exception { int sc = test(makeToken(KEY, makeClaimMap("inexistent_claim", "user")), Optional.of("x-custom-header"), false);//w ww. j a va2 s . c o m assertEquals(401, sc); }
From source file:io.knotx.mocks.knot.KnotContextKeys.java
private Optional<Object> toJson(Buffer buffer) { return Optional .of(buffer.toString().trim().charAt(0) == '{' ? buffer.toJsonObject() : buffer.toJsonArray()); }
From source file:org.homiefund.web.controllers.SignUpController.java
@PostMapping("/signup/") public String submit(@Valid @ModelAttribute UserRegistrationForm userRegistrationForm, BindingResult result, Model model) {// www.j a v a 2 s . c o m log.info(userRegistrationForm.getName()); if (result.hasErrors()) { clearPasswords(userRegistrationForm); return "signup"; } try { Optional<InvitationDTO> invitation; if (StringUtils.isEmpty(userRegistrationForm.getInviteToken())) { invitation = Optional.empty(); } else { InvitationDTO invite = new InvitationDTO(); invite.setHash(userRegistrationForm.getInviteToken()); invitation = Optional.of(invite); } userRegistrationForm.setPassword(bCryptPasswordEncoder.encode(userRegistrationForm.getPassword())); registrationService.register(mapper.map(userRegistrationForm, UserDTO.class), invitation); } catch (FieldException fe) { result.rejectValue(fe.getField(), fe.getMessage()); clearPasswords(userRegistrationForm); return "signup"; } return "redirect:/"; }
From source file:co.runrightfast.core.utils.ConfigUtils.java
static Optional<Integer> getInt(final Config config, final String path, final String... paths) { if (!hasPath(config, path, paths)) { return Optional.empty(); }/*from w w w . j a v a2 s.c o m*/ return Optional.of(config.getInt(configPath(path, paths))); }
From source file:com.khartec.waltz.web.endpoints.auth.AuthenticationEndpoint.java
private Optional<Filter> instantiateFilter(String className) { try {// w w w . j a v a 2 s. co m LOG.info("Setting authentication filter to: " + className); Filter filter = (Filter) Class.forName(className).getConstructor(SettingsService.class) .newInstance(settingsService); return Optional.of(filter); } catch (Exception e) { LOG.error("Cannot instantiate authentication filter class: " + className, e); return Optional.empty(); } }