RestMockResponse extends AbstractMockResponse<RESTMockResponseConfig> implements MediaType { protected String getEncodingValue(String[] parameters) { String encoding = null; for (int i = 0; i < parameters.length; i++) { if (parameters[i].trim().startsWith("charset=")) { String[] encodingParts = parameters[i].split("="); if (encodingParts.length > 1) { encoding = encodingParts[1]; return encoding; } } } return encoding; } RestMockResponse(RestMockAction action, RESTMockResponseConfig config); @Override int getAttachmentCount(); @Override Attachment getAttachmentAt(int index); @Override Attachment[] getAttachmentsForPart(String partName); @Override MessagePart.AttachmentPart[] getDefinedAttachmentParts(); @Override MessagePart.AttachmentPart getAttachmentPart(String partName); @Override void addAttachmentsChangeListener(PropertyChangeListener listener); @Override void removeAttachmentsChangeListener(PropertyChangeListener listener); @Override boolean isMultipartEnabled(); @Override boolean isMtomEnabled(); @Override boolean isInlineFilesEnabled(); @Override boolean isEncodeAttachments(); @Override Attachment.AttachmentEncoding getAttachmentEncoding(String partName); @Override Attachment[] getAttachments(); @Override MockOperation getMockOperation(); @Override String getScriptHelpUrl(); @Override Attachment attachFile(File file, boolean cache); @Override void removeAttachment(Attachment attachment); @Override PropertyExpansion[] getPropertyExpansions(); @Override String getPropertiesLabel(); @Override String getContentType(); @Override long getResponseDelay(); @Override boolean isForceMtom(); @Override boolean isStripWhitespaces(); @Override String getMediaType(); @Override void setMediaType(String mediaType); void setContentType(String contentType); final static String MOCKRESULT_PROPERTY; static final String ICON_NAME; }
@Test public void getsCorrectEncodingValue() throws Exception { String contentType = "application/atom+xml; charset=UTF-8"; String[] parameters = contentType.split(";"); assertThat(restMockResponse.getEncodingValue(parameters), is("UTF-8")); }
@Test public void getsEncodingValueFromMultipleParameters() throws Exception { String contentType = "application/atom+xml; charset=UTF-8; type=feed"; String[] parameters = contentType.split(";"); assertThat(restMockResponse.getEncodingValue(parameters), is("UTF-8")); }
@Test public void getsEncodingValueWhenEncodingValueIsLastParam() throws Exception { String contentType = "application/atom+xml; type=feed; charset=UTF-8; "; String[] parameters = contentType.split(";"); assertThat(restMockResponse.getEncodingValue(parameters), is("UTF-8")); }
@Test public void doesNoGetAnyEncodingValueWhenContentTypeDoesNotHaveEncoding() throws Exception { String contentType = "application/atom+xml; type=feed; boo=false"; String[] parameters = contentType.split(";"); assertNull(restMockResponse.getEncodingValue(parameters)); }