@Test
 @DirtiesContext
 public void testRoles() {
   this.roleController.stopLifecyclesInRole("foo");
   @SuppressWarnings("unchecked")
   MultiValueMap<String, SmartLifecycle> lifecycles =
       TestUtils.getPropertyValue(this.roleController, "lifecycles", MultiValueMap.class);
   assertEquals(2, lifecycles.size());
   assertEquals(2, lifecycles.get("foo").size());
   assertEquals(1, lifecycles.get("bar").size());
   assertFalse(this.serviceActivatorEndpoint.isRunning());
   assertFalse(this.sendAsyncHandler.isRunning());
   assertEquals(2, lifecycles.size());
   assertEquals(2, lifecycles.get("foo").size());
 }
 /**
  * Builds the authorization header. The elements in additionalParameters are expected to not be
  * encoded.
  */
 public String buildAuthorizationHeaderValue(
     HttpMethod method,
     URI targetUrl,
     Map<String, String> oauthParameters,
     MultiValueMap<String, String> additionalParameters,
     String consumerSecret,
     String tokenSecret) {
   StringBuilder header = new StringBuilder();
   header.append("OAuth ");
   for (Entry<String, String> entry : oauthParameters.entrySet()) {
     header
         .append(oauthEncode(entry.getKey()))
         .append("=\"")
         .append(oauthEncode(entry.getValue()))
         .append("\", ");
   }
   MultiValueMap<String, String> collectedParameters =
       new LinkedMultiValueMap<String, String>(
           (int) ((oauthParameters.size() + additionalParameters.size()) / .75 + 1));
   collectedParameters.setAll(oauthParameters);
   collectedParameters.putAll(additionalParameters);
   String baseString = buildBaseString(method, getBaseStringUri(targetUrl), collectedParameters);
   String signature = calculateSignature(baseString, consumerSecret, tokenSecret);
   header
       .append(oauthEncode("oauth_signature"))
       .append("=\"")
       .append(oauthEncode(signature))
       .append("\"");
   return header.toString();
 }
  @Test
  public void parseMatrixVariablesString() {
    MultiValueMap<String, String> variables;

    variables = WebUtils.parseMatrixVariables(null);
    assertEquals(0, variables.size());

    variables = WebUtils.parseMatrixVariables("year");
    assertEquals(1, variables.size());
    assertEquals("", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012");
    assertEquals(1, variables.size());
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012;colors=red,blue,green");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables(";year=2012;colors=red,blue,green;");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("colors=red;colors=blue;colors=green");
    assertEquals(1, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
  }
  /**
   * Decode the given matrix variables unless {@link #setUrlDecode(boolean)} is set to {@code true}
   * in which case it is assumed the URL path from which the variables were extracted is already
   * decoded through a call to {@link #getLookupPathForRequest(ServerWebExchange)}.
   *
   * @param exchange current exchange
   * @param vars URI variables extracted from the URL path
   * @return the same Map or a new Map instance
   */
  public MultiValueMap<String, String> decodeMatrixVariables(
      ServerWebExchange exchange, MultiValueMap<String, String> vars) {

    if (this.urlDecode) {
      return vars;
    }
    MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap<>(vars.size());
    for (String key : vars.keySet()) {
      for (String value : vars.get(key)) {
        decodedVars.add(key, decode(exchange, value));
      }
    }
    return decodedVars;
  }
  @Test
  public void testPartListBinding() {

    PartListBean bean = new PartListBean();
    partListServlet.setBean(bean);

    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
    parts.add("partList", "first value");
    parts.add("partList", "second value");
    Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
    parts.add("partList", logo);

    template.postForLocation(baseUrl + "/partlist", parts);

    assertNotNull(bean.getPartList());
    assertEquals(parts.size(), bean.getPartList().size());
  }
 @Test
 @SuppressWarnings("unchecked")
 public void getRequestOk() throws Exception {
   MockHttpServletRequest request = new MockHttpServletRequest();
   request.setMethod("GET");
   request.setParameter("foo", "bar");
   MockHttpServletResponse response = new MockHttpServletResponse();
   defaultAdapter.handleRequest(request, response);
   assertEquals(HttpServletResponse.SC_OK, response.getStatus());
   Message<?> message = requests.receive(0);
   assertNotNull(message);
   Object payload = message.getPayload();
   assertTrue(payload instanceof MultiValueMap);
   MultiValueMap<String, String> map = (MultiValueMap<String, String>) payload;
   assertEquals(1, map.size());
   assertEquals("foo", map.keySet().iterator().next());
   assertEquals(1, map.get("foo").size());
   assertEquals("bar", map.getFirst("foo"));
   assertNotNull(TestUtils.getPropertyValue(defaultAdapter, "errorChannel"));
 }