Search in sources :

Example 1 with FileInput

use of org.apache.camel.component.bonita.api.model.FileInput in project camel by apache.

the class BonitaAPIUtil method prepareInputs.

public Map<String, Serializable> prepareInputs(ProcessDefinitionResponse processDefinition, Map<String, Serializable> inputs) throws Exception {
    for (Entry<String, Serializable> entry : inputs.entrySet()) {
        if (entry.getValue() instanceof FileInput) {
            FileInput file = (FileInput) entry.getValue();
            String tmpFile = uploadFile(processDefinition, file).getTempPath();
            HashMap<String, Serializable> fileInput = new HashMap<String, Serializable>();
            fileInput.put("filename", file.getFilename());
            fileInput.put("tempPath", tmpFile);
            entry.setValue(fileInput);
        }
    }
    return inputs;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileInput(org.apache.camel.component.bonita.api.model.FileInput)

Example 2 with FileInput

use of org.apache.camel.component.bonita.api.model.FileInput in project camel by apache.

the class BonitaAPIUtilPrepareInputsTest method testPrepareInputsOneFile.

@Test
public void testPrepareInputsOneFile() throws Exception {
    Map<String, Serializable> rawInputs = new HashMap<String, Serializable>();
    FileInput file = new FileInput("filename", "String".getBytes());
    rawInputs.put("myVariable", 1);
    rawInputs.put("filename", file);
    BonitaAPIUtil bonitaApiUtilMod = Mockito.spy(bonitaApiUtil);
    UploadFileResponse uploadFileResponse = new UploadFileResponse();
    uploadFileResponse.setTempPath("temp");
    Mockito.doReturn(uploadFileResponse).when(bonitaApiUtilMod).uploadFile(Matchers.any(), Matchers.any());
    Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
    assertEquals(rawInputs.size(), inputs.size());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileInput(org.apache.camel.component.bonita.api.model.FileInput) UploadFileResponse(org.apache.camel.component.bonita.api.model.UploadFileResponse) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with FileInput

use of org.apache.camel.component.bonita.api.model.FileInput in project camel by apache.

the class BonitaAPIUtilPrepareInputsTest method testPrepareInputsFileType.

@Test
public void testPrepareInputsFileType() throws Exception {
    Map<String, Serializable> rawInputs = new HashMap<String, Serializable>();
    FileInput file = new FileInput("filename", "String".getBytes());
    rawInputs.put("filename", file);
    BonitaAPIUtil bonitaApiUtilMod = Mockito.spy(bonitaApiUtil);
    UploadFileResponse uploadFileResponse = new UploadFileResponse();
    uploadFileResponse.setTempPath("temp");
    Mockito.doReturn(uploadFileResponse).when(bonitaApiUtilMod).uploadFile(Matchers.any(), Matchers.any());
    Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
    assertTrue(Map.class.isInstance(inputs.get("filename")));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileInput(org.apache.camel.component.bonita.api.model.FileInput) UploadFileResponse(org.apache.camel.component.bonita.api.model.UploadFileResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with FileInput

use of org.apache.camel.component.bonita.api.model.FileInput in project camel by apache.

the class BonitaAPIUtilPrepareInputsTest method testPrepareInputsTempFilePath.

@Test
public void testPrepareInputsTempFilePath() throws Exception {
    Map<String, Serializable> rawInputs = new HashMap<String, Serializable>();
    FileInput file = new FileInput("filename", "String".getBytes());
    rawInputs.put("filename", file);
    BonitaAPIUtil bonitaApiUtilMod = Mockito.spy(bonitaApiUtil);
    UploadFileResponse uploadFileResponse = new UploadFileResponse();
    uploadFileResponse.setTempPath("temp");
    Mockito.doReturn(uploadFileResponse).when(bonitaApiUtilMod).uploadFile(Matchers.any(), Matchers.any());
    Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
    Map<String, Serializable> fileMap = (Map<String, Serializable>) inputs.get("filename");
    assertEquals("temp", fileMap.get("tempPath"));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileInput(org.apache.camel.component.bonita.api.model.FileInput) UploadFileResponse(org.apache.camel.component.bonita.api.model.UploadFileResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 FileInput (org.apache.camel.component.bonita.api.model.FileInput)4 UploadFileResponse (org.apache.camel.component.bonita.api.model.UploadFileResponse)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Map (java.util.Map)2