@Override public List<String> get(Object key) { List<String> values = this.headers.get(key); return (values != null ? Collections.unmodifiableList(values) : null); }
@Test public void putShouldOverrideExisting() { this.headers.add("TestHeader", "first"); this.headers.put("TestHeader", Arrays.asList("override")); assertEquals("override", this.headers.getFirst("TestHeader")); assertEquals(1, this.headers.get("TestHeader").size()); }
@SuppressWarnings("unchecked") private List<String[]> getConditionClasses(AnnotatedTypeMetadata metadata) { MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true); Object values = (attributes != null ? attributes.get("value") : null); return (List<String[]>) (values != null ? values : Collections.emptyList()); }
@RequestMapping("/hotels/{hotel}/bookings/{booking}-{other}") public void handle(@PathVariable("hotel") String hotel, @PathVariable int booking, @PathVariable String other, @MatrixVariable MultiValueMap<String, String> params) { assertEquals("Invalid path variable value", "42", hotel); assertEquals("Invalid path variable value", 21, booking); assertEquals(Arrays.asList("1", "2", "3"), params.get("q")); assertEquals("R", params.getFirst("r")); }
@Override public List<MultipartFile> getFiles(String name) { List<MultipartFile> multipartFiles = getMultipartFiles().get(name); if (multipartFiles != null) { return multipartFiles; } else { return Collections.emptyList(); } }
@Test public void addTargetRequestParamsNullValue() { MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("key", "abc"); params.add("key", " "); params.add("key", null); FlashMap flashMap = new FlashMap(); flashMap.addTargetRequestParams(params); assertEquals(1, flashMap.getTargetRequestParams().size()); assertEquals(1, flashMap.getTargetRequestParams().get("key").size()); assertEquals("abc", flashMap.getTargetRequestParams().getFirst("key")); }
@Override @Nullable public AnnotationMetadata getImportingClassFor(String importedClass) { return CollectionUtils.lastElement(this.imports.get(importedClass)); }
@Override public List<MultipartFile> getFiles(String name) { List<MultipartFile> multipartFiles = this.multipartFiles.get(name); if (multipartFiles != null) { return multipartFiles; } else { return Collections.emptyList(); } }
/** * Assert request query parameter values. */ public static RequestMatcher queryParam(final String name, final String... expectedValues) { return request -> { MultiValueMap<String, String> params = getQueryParams(request); assertValueCount("query param", name, params, expectedValues.length); for (int i = 0 ; i < expectedValues.length; i++) { assertEquals("Query param [" + name + "]", expectedValues[i], params.get(name).get(i)); } }; }
/** * Return the events that the specified listener has received. The list of events * is ordered according to their reception order. */ public List<Object> getEvents(Identifiable listener) { return this.content.get(listener.getId()); }
private void insertQueryParams() { StringBuilder query = new StringBuilder(); for (String key : this.queryParams.keySet()) { for (String value : this.queryParams.get(key)) { this.servletRequest.addParameter(key, value); query.append(query.length() > 0 ? "&" : "").append(key).append("=").append(value); } } this.servletRequest.setQueryString(query.toString()); }
@Test public void fromMethodNameWithPathVarAndRequestParam() { UriComponents uriComponents = fromMethodName( ControllerWithMethods.class, "methodForNextPage", "1", 10, 5).build(); assertThat(uriComponents.getPath(), is("/something/1/foo")); MultiValueMap<String, String> queryParams = uriComponents.getQueryParams(); assertThat(queryParams.get("limit"), contains("5")); assertThat(queryParams.get("offset"), contains("10")); }
@Test public void queryParamWithoutValueWithoutEquals() { UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar").build(); assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar")); // TODO [SPR-13537] Change equalTo(null) to equalTo(""). assertThat(uriComponents.getQueryParams().get("bar").get(0), equalTo(null)); }
@Test public void queryParams() throws Exception { MultiValueMap<String, String> params = createHttpRequest("/path?a=A&b=B").getQueryParams(); assertEquals(2, params.size()); assertEquals(Collections.singletonList("A"), params.get("a")); assertEquals(Collections.singletonList("B"), params.get("b")); }
@Test public void getAllAnnotationAttributesOnClassWithLocalAnnotation() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(TxConfig.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on TxConfig", attributes); assertEquals("value for TxConfig.", asList("TxConfig"), attributes.get("value")); }
/** * Note: this functionality is required by {@link org.springframework.context.annotation.ProfileCondition}. * @see org.springframework.core.env.EnvironmentSystemIntegrationTests */ @Test public void getAllAnnotationAttributesOnClassWithMultipleComposedAnnotations() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(TxFromMultipleComposedAnnotations.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on TxFromMultipleComposedAnnotations", attributes); assertEquals("value for TxFromMultipleComposedAnnotations.", asList("TxInheritedComposed", "TxComposed"), attributes.get("value")); }
@Test public void queryParamsWithEmptyValue() throws Exception { MultiValueMap<String, String> params = createHttpRequest("/path?a=").getQueryParams(); assertEquals(1, params.size()); assertEquals(Collections.singletonList(""), params.get("a")); }
@Test public void queryParamsWithNoValue() throws Exception { MultiValueMap<String, String> params = createHttpRequest("/path?a").getQueryParams(); assertEquals(1, params.size()); assertEquals(Collections.singletonList(null), params.get("a")); }
@Test public void handleMatchMatrixVariablesDecoding() { MockServerHttpRequest request = method(HttpMethod.GET, URI.create("/cars;mvar=a%2Fb")).build(); ServerWebExchange exchange = MockServerWebExchange.from(request); handleMatch(exchange, "/{cars}"); MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "cars"); Map<String, String> uriVariables = getUriTemplateVariables(exchange); assertNotNull(matrixVariables); assertEquals(Collections.singletonList("a/b"), matrixVariables.get("mvar")); assertEquals("cars", uriVariables.get("cars")); }
@Test public void registerSubscriptionWithDestinationPattern() { String sessId = "sess01"; String subsId = "subs01"; String destPattern = "/topic/PRICE.STOCK.*.IBM"; String dest = "/topic/PRICE.STOCK.NASDAQ.IBM"; this.registry.registerSubscription(subscribeMessage(sessId, subsId, destPattern)); MultiValueMap<String, String> actual = this.registry.findSubscriptions(createMessage(dest)); assertNotNull(actual); assertEquals("Expected one element " + actual, 1, actual.size()); assertEquals(Collections.singletonList(subsId), actual.get(sessId)); }