List of usage examples for java.util LinkedHashMap get
public V get(Object key)
From source file:org.raxa.module.raxacore.web.v1_0.controller.DrugPurchaseOrderControllerTest.java
/** * @see DrugPurchaseOrderController#updateDrugPurchaseOrder(String, SimpleObject, HttpServletRequest, HttpServletResponse) * @verifies a new patient list is created *///from w w w . j a v a 2 s.co m @Test public void updateDrugPurchaseOrder_shouldUpdateADrugPurchaseOrder() throws Exception { int before = service.getAllDrugPurchaseOrders().size(); String json = "{ \"name\":\"Test DrugPurchaseOrder Change\",\"description\":\"Test Alert\"}"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); controller.updateDrugPurchaseOrder("68547121-1b70-465c-99ee-c9dfd95e7d41", post, request, response); Assert.assertEquals(before, service.getAllDrugPurchaseOrders().size()); String results = controller.getAllDrugPurchaseOrders(request, response); LinkedHashMap updatedDrugPurchaseOrder = (LinkedHashMap) ((ArrayList) SimpleObject.parseJson(results) .get("results")).get(0); Assert.assertEquals("Test DrugPurchaseOrder Change", updatedDrugPurchaseOrder.get("name")); }
From source file:com.nestlabs.sdk.StructureTest.java
@Test public void testWhereDescribeContents_shouldReturnZero() { try {//from ww w .ja v a 2 s . c o m String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_STRUCTURE_JSON), "utf-8"); Structure structure = mapper.readValue(json, Structure.class); LinkedHashMap<String, Structure.Where> wheres = structure.getWheres(); for (String whereId : wheres.keySet()) { assertEquals(wheres.get(whereId).describeContents(), 0); } } catch (IOException e) { e.printStackTrace(); Assert.fail(); } }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
/** * Applies a limit to the map. All values after limit will be summed and placed in the return map with key {@code * limitLabel}. Zero or NaN values do not count towards the limit. * * @param map The map to limit. Assumed use case is that the map is already value sorted descending. * @return limited map.//from w ww . j a v a2s .c o m */ public static LinkedHashMap<String, Double> getLimitedMap(Map<String, Double> map, Integer limit, String limitLabel) { LinkedHashMap<String, Double> mapValueSort = new LinkedHashMap<String, Double>(limit); //add limit by default if the record size is greater than the limit. if (limit < map.size()) { mapValueSort.put(limitLabel, 0.0); } //combine any value after limit into a summed bucket int i = 0; for (String key : map.keySet()) { Double value = map.get(key); if (i < limit) { mapValueSort.put(key, value); } else { //we've hit the limit, now accumulate Double val = mapValueSort.get(limitLabel); if (value != null && !Double.isNaN(value)) { mapValueSort.put(limitLabel, val + value); } } //if it is not zero/null count it towards limit if (value != null && !Double.isNaN(value) && value > 0) { i++; } } return mapValueSort; }
From source file:org.openmrs.module.webservices.rest.web.RestUtilTest.java
/** * @see RestUtil#wrapErrorResponse(Exception,String) * @verifies set stack trace code if available *//*from w w w . j a v a 2 s . co m*/ @Test public void wrapErrorResponse_shouldSetStackTraceCodeAndDetailIfAvailable() throws Exception { Exception mockException = Mockito.mock(Exception.class); Mockito.when(mockException.getMessage()).thenReturn("exceptionmessage"); StackTraceElement ste = new StackTraceElement("org.mypackage.myclassname", "methodName", "fileName", 149); Mockito.when(mockException.getStackTrace()).thenReturn(new StackTraceElement[] { ste }); SimpleObject returnObject = RestUtil.wrapErrorResponse(mockException, "wraperrorresponsemessage"); LinkedHashMap errorResponseMap = (LinkedHashMap) returnObject.get("error"); Assert.assertEquals("org.mypackage.myclassname:149", errorResponseMap.get("code")); }
From source file:com.logsniffer.reader.filter.support.JsonParseFilterTest.java
@SuppressWarnings("unchecked") @Test/*from ww w . ja va2s. c o m*/ public void testFiltering() { f.setTargetField("jsonObj"); f.setSourceField("jsonStr"); fields.put("jsonStr", "{'abc':'def'}"); // Check f.filter(fields); Assert.assertNotNull(fields.get("jsonObj")); Assert.assertEquals("def", ((Map<String, Object>) fields.get("jsonObj")).get("abc")); LinkedHashMap<String, FieldBaseTypes> types = new LinkedHashMap<>(); f.filterKnownFields(types); Assert.assertEquals(1, types.size()); Assert.assertEquals(FieldBaseTypes.OBJECT, types.get("jsonObj")); }
From source file:com.fortify.processrunner.octane.processor.ProcessorOctaneSubmitIssueForVulnerabilities.java
@Override protected SubmittedIssue submitIssue(Context context, LinkedHashMap<String, Object> issueData) { IContextOctane contextOctane = context.as(IContextOctane.class); OctaneAuthenticatingRestConnection conn = OctaneConnectionFactory.getConnection(context); issueData.put("name", StringUtils.abbreviate((String) issueData.get("name"), 254)); return conn.submitIssue(new OctaneSharedSpaceAndWorkspaceId(contextOctane.getOctaneSharedSpaceUid(), contextOctane.getOctaneWorkspaceId()), issueData); }
From source file:io.stallion.restfulEndpoints.QueryToPager.java
protected void process() { // ?filters=&search=&page=&sort=&filter_by... Map<String, String> params = this.request.getQueryParams(); String search = params.getOrDefault("search", null); if (!empty(search)) { if (!empty(_searchFields)) { this.chain = chain.search(search, asArray(_searchFields, String.class)); } else {/*w ww. j a va 2 s. c o m*/ Log.warn("Search included, but no search fields defined"); } } String filters = params.getOrDefault("filters", null); if (!empty(filters)) { List<LinkedHashMap> filterObjects = JSON.parseList(filters); for (LinkedHashMap<String, Object> o : filterObjects) { String field = o.get("name").toString(); if (!_allFilters && !_allowedFilters.contains(field)) { Log.warn("Filter not allowed: " + field); continue; } Object value = o.get("value"); if (value instanceof Collection) { value = new ArrayList((Collection) value); } String operation = (String) o.getOrDefault("op", "="); this.chain = chain.filter(field, value, operation); } } String sort = or(params.getOrDefault("sort", null), defaultSort); if (!empty(sort)) { SortDirection dir = SortDirection.ASC; if (sort.startsWith("-")) { sort = sort.substring(1); dir = SortDirection.DESC; } if (!_allSorts && !_allowedSortable.contains(sort)) { Log.warn("Sort not allowed: " + sort); } else { this.chain = chain.sortBy(sort, dir); } } for (String filter : request.getQueryParamAsList("filter_by")) { if (empty(filter) || !filter.contains(":")) { continue; } String[] parts = StringUtils.split(filter, ":", 3); String key = parts[0]; if (_allFilters && !_allowedFilters.contains(key)) { Log.warn("Filter not allowed: " + key); continue; } String val; String op = "eq"; if (parts.length > 2) { op = parts[1]; val = parts[2]; } else { val = parts[1]; } this.chain = chain.filter(key, val, op); } }
From source file:com.fortify.processrunner.common.processor.AbstractBugTrackerFieldsBasedProcessor.java
/** * Utility method for filtering an input map based on the given array of keys. * @param inputMap//from w w w. j ava2 s . c o m * @param keys * @return */ private LinkedHashMap<String, TemplateExpression> getFilteredMap( LinkedHashMap<String, TemplateExpression> inputMap, String[] keys) { LinkedHashMap<String, TemplateExpression> result = new LinkedHashMap<String, TemplateExpression>( keys.length); for (String key : keys) { result.put(key, inputMap.get(key)); } return result; }
From source file:hd3gtv.mydmam.useraction.fileoperation.UAFileOperationTrash.java
public UACapability createCapability(LinkedHashMap<String, ?> internal_configuration) { if (internal_configuration.containsKey("trash_directory")) { trash_directory_name = (String) internal_configuration.get("trash_directory"); }/* ww w.ja va 2s. com*/ return new Capability(); }
From source file:com.company.eleave.leave.rest.ITAnnualBalanceLeaveController.java
@Test public void testGetLeavesForEmployee() throws Exception { final String contentAsString = mockMvc .perform(get(request(RestURI.ANNUAL_BALANCE_LEAVES_BY_EMPLOYEE, EMPLOYEE_ID))) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); List<LinkedHashMap> result = new ObjectMapper().readValue(contentAsString, List.class); Assert.assertEquals(3, result.size()); final LinkedHashMap firstAnnualBalanceLeave = result.stream().filter(map -> ((int) map.get("id") == 1)) .findAny().get();//from ww w. j a v a2 s .c om Assert.assertEquals(20, (int) firstAnnualBalanceLeave.get("leaveDaysAllowed")); Assert.assertEquals(15, (int) firstAnnualBalanceLeave.get("leaveDaysRemaining")); Assert.assertEquals(10, (int) firstAnnualBalanceLeave.get("leaveTypeId")); Assert.assertEquals("Standard holiday", firstAnnualBalanceLeave.get("leaveTypeName")); Assert.assertEquals("2016-12-12", firstAnnualBalanceLeave.get("validityDate")); }