DefaultBodyFactory implements BodyFactory { @Override public void buildBody(RequestBuilder requestBuilder, RestAction<?> action) throws ActionException { if (action.hasFormParams()) { assignBodyFromForm(requestBuilder, action); } else { assignBodyFromSerialization(requestBuilder, action); } } @Inject  DefaultBodyFactory(
            Provider<Set<Serialization>> serializationsProvider,
            UriFactory uriFactory); @Override void buildBody(RequestBuilder requestBuilder, RestAction<?> action);  }
@Test public void build_noFormParamsNoBody_setsExplicitNullAsRequestData() throws ActionException { RestAction<Void> action = new UnsecuredRestAction(DELETE, RELATIVE_PATH); factory.buildBody(requestBuilder, action); verify(requestBuilder).setRequestData(isNull(String.class)); verify(requestBuilder, never()).setHeader(anyString(), anyString()); }
@Test public void build_formParams_requestContainsOnlyFormParams() throws ActionException { ExposedRestAction<Void> action = new SecuredRestAction(GET, RELATIVE_PATH); action.addParam(new FormParameter("Key1", "Some Value", null, urlUtils)); factory.buildBody(requestBuilder, action); verify(requestBuilder).setRequestData(eq(QUERY_STRING)); verify(requestBuilder).setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); }
@Test(expected = ActionException.class) public void build_body_noSerializer_throws(Serialization serialization) throws ActionException { Object unserializedObject = new Object(); String serializationKey = "meta"; ExposedRestAction<Void> action = new SecuredRestAction(GET, RELATIVE_PATH); action.setBodyParam(unserializedObject); action.setBodyClass(serializationKey); given(serialization.canSerialize(eq(serializationKey), anyListOf(ContentType.class))).willReturn(false); factory.buildBody(requestBuilder, action); }