/** * Copyright (C) 2015 Bonitasoft S.A. * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2.0 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.bonitasoft.web.designer.utils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import javax.servlet.http.Part; public class FakeHttpRequestPart implements Part { private byte[] content; private String name; private String contentType; private InputStream stream; public static FakeHttpRequestPart aPart(String name, byte[] content) { return new FakeHttpRequestPart(name, content); } public FakeHttpRequestPart(String name, byte[] content) { this.name = name; this.content = content; this.stream = new ByteArrayInputStream(content); } public FakeHttpRequestPart setContentType(String contentType) { this.contentType = contentType; return this; } @Override public InputStream getInputStream() throws IOException { return stream; } @Override public String getContentType() { return contentType; } @Override public String getName() { return name; } @Override public long getSize() { return content.length; } @Override public void write(String fileName) throws IOException { // TODO Auto-generated method stub } @Override public void delete() throws IOException { // TODO Auto-generated method stub } @Override public String getHeader(String name) { // TODO Auto-generated method stub return null; } @Override public Collection<String> getHeaders(String name) { // TODO Auto-generated method stub return null; } @Override public Collection<String> getHeaderNames() { // TODO Auto-generated method stub return null; } }