List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:org.openwms.tms.PrioritizeTODocumentation.java
public @Test void prioritizeTO() throws Exception { // setup .../*from w w w . j a va 2 s . com*/ CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); given(commonGateway.getTransportUnit(KNOWN)) .willReturn(Optional.of(new TransportUnit(KNOWN, INIT_LOC, ERR_LOC_STRING))); mockMvc.perform(get(TMSConstants.ROOT_ENTITIES + "/" + vo.getpKey())).andExpect(status().isOk()) .andExpect(jsonPath("priority", is("HIGHEST"))); // test ... vo.setPriority(PriorityLevel.NORMAL.toString()); mockMvc.perform(patch(TMSConstants.ROOT_ENTITIES).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(vo))).andExpect(status().isNoContent()) .andDo(document("to-patch-priority-ok")); mockMvc.perform(get(TMSConstants.ROOT_ENTITIES + "/" + vo.getpKey())).andExpect(status().isOk()) .andExpect(jsonPath("priority", is("NORMAL"))); }
From source file:nu.yona.server.messaging.service.DisclosureRequestMessageDto.java
public static DisclosureRequestMessageDto createInstance(DisclosureRequestMessage messageEntity, SenderInfo senderInfo) {/*from w w w . j av a 2 s . c o m*/ GoalConflictMessage targetGoalConflictMessage = messageEntity.getTargetGoalConflictMessage(); return new DisclosureRequestMessageDto(messageEntity.getId(), messageEntity.getCreationTime(), messageEntity.isRead(), senderInfo, messageEntity.getMessage(), messageEntity.getStatus(), Optional.of(targetGoalConflictMessage.getOriginGoalConflictMessage().getId()), targetGoalConflictMessage.getGoal().getId(), targetGoalConflictMessage.getActivity().getStartTime().toLocalDate()); }
From source file:com.ikanow.aleph2.data_model.utils.TestCrudServiceUtils.java
@Test public void test_readOnlyManagementCrudService() { final MockManagementCrudService<String> mock_crud = new MockManagementCrudService<String>(); final ReadOnlyManagementCrudService<String> ro_crud = new ReadOnlyManagementCrudService<>(mock_crud); // Add a few dummy entries mock_crud.setMockValues(Arrays.asList("test1", "test2")); test_readOnly(ro_crud, mock_crud);/* w w w .ja v a2 s. c o m*/ assertEquals(Optional.of(ro_crud), ro_crud.getCrudService()); }
From source file:com.orange.ngsi2.model.SubscriptionTest.java
@Test public void serializationSubscriptionTest() throws JsonProcessingException, MalformedURLException { ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter()); SubjectEntity subjectEntity = new SubjectEntity(); subjectEntity.setId(Optional.of("Bcn_Welt")); subjectEntity.setType(Optional.of("Room")); Condition condition = new Condition(); condition.setAttributes(Collections.singletonList("temperature")); condition.setExpression("q", "temperature>40"); SubjectSubscription subjectSubscription = new SubjectSubscription(Collections.singletonList(subjectEntity), condition);//from w w w .j a v a 2 s . co m List<String> attributes = new ArrayList<>(); attributes.add("temperature"); attributes.add("humidity"); Notification notification = new Notification(attributes, new URL("http://localhost:1234")); notification.setThrottling(Optional.of(new Long(5))); notification.setTimesSent(12); notification.setLastNotification(Instant.parse("2015-10-05T16:00:00.10Z")); notification.setHeader("X-MyHeader", "foo"); notification.setQuery("authToken", "bar"); notification.setAttrsFormat(Optional.of(Notification.Format.keyValues)); String json = writer.writeValueAsString(new Subscription("abcdefg", subjectSubscription, notification, Instant.parse("2016-04-05T14:00:00.20Z"), Subscription.Status.active)); assertEquals(jsonString, json); }
From source file:org.openwms.tms.ChangeStateDocumentation.java
public @Test void turnBackState() throws Exception { // setup .../*from w ww .j a v a 2 s. co m*/ CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); vo.setState(TransportOrderState.INITIALIZED.toString()); given(commonGateway.getTransportUnit(KNOWN)) .willReturn(Optional.of(new TransportUnit(KNOWN, INIT_LOC, ERR_LOC_STRING))); // test ... mockMvc.perform(patch(TMSConstants.ROOT_ENTITIES).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(vo))).andExpect(status().isBadRequest()) .andExpect(jsonPath("messageKey", is(TMSMessageCodes.TO_STATE_CHANGE_BACKWARDS_NOT_ALLOWED))) .andDo(document("to-patch-state-change-back")); }
From source file:lumbermill.internal.http.PostHandler.java
public PostHandler(Supplier<HttpHandler<IN, ?>> httpHandlerSupplier, OnPostCreatedCallback callback) { this.httpHandlerSupplier = Optional.of(httpHandlerSupplier); this.callback = callback; }
From source file:co.runrightfast.core.utils.ConfigUtils.java
static Optional<Double> getDouble(final Config config, final String path, final String... paths) { if (!hasPath(config, path, paths)) { return Optional.empty(); }//from w ww . j a va 2s. c om return Optional.of(config.getDouble(configPath(path, paths))); }
From source file:tds.assessment.web.endpoints.ItemControllerTest.java
@Test public void itShouldReturnItemMetadataForStimulus() { ItemFileMetadata itemFileMetadata = ItemFileMetadata.create(ItemFileType.STIMULUS, "test", "test", "test"); when(mockItemService.findItemFileMetadataByStimulusKey("SBAC_PT", 1, 2)) .thenReturn(Optional.of(itemFileMetadata)); ResponseEntity<ItemFileMetadata> response = itemController.findItemFileMetadata("SBAC_PT", 1, 2L, null); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isEqualTo(itemFileMetadata); }
From source file:com.ikanow.aleph2.security.service.IkanowV1CommunityRoleProvider.java
@SuppressWarnings("unchecked") protected void initDb() { if (_core_management_db == null) { _core_management_db = _context.getCoreManagementDbService(); }/*from w w w .jav a2 s .c o m*/ if (_underlying_management_db == null) { _underlying_management_db = _context.getService(IManagementDbService.class, Optional.empty()).get(); } String personOptions = "social.person"; personDb = _underlying_management_db .getUnderlyingPlatformDriver(ICrudService.class, Optional.of(personOptions)).get(); logger.debug("PersonDB:" + personDb); }
From source file:io.kamax.mxisd.backend.sql.GenericSqlDirectoryProvider.java
protected Optional<Result> processRow(ResultSet rSet) throws SQLException { Result item = new Result(); item.setUserId(rSet.getString(1));/* w w w. j av a 2s .c o m*/ item.setDisplayName(rSet.getString(2)); return Optional.of(item); }