You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/11/01 16:06:34 UTC
[3/8] camel git commit: CAMEL-10350: Add Bonita Component
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterAlreadyConnectedTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterAlreadyConnectedTest.java b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterAlreadyConnectedTest.java
new file mode 100644
index 0000000..06b7c07
--- /dev/null
+++ b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterAlreadyConnectedTest.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.bonita.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.core.Cookie;
+
+import org.apache.camel.component.bonita.api.filter.BonitaAuthFilter;
+import org.apache.camel.component.bonita.api.util.BonitaAPIConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class BonitaAuthFilterAlreadyConnectedTest {
+
+
+ @Mock
+ private ClientRequestContext requestContext;
+
+
+
+ @Before
+ public void setup() {
+ Map<String,Cookie> resultCookies = new HashMap<>();
+ resultCookies.put("JSESSIONID", new Cookie("JSESSIONID","something"));
+ Mockito.when(requestContext.getCookies()).thenReturn(resultCookies);
+
+ }
+
+
+ @Test
+ public void testAlreadyConnected() throws Exception{
+ BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("hostname", "port", "username", "password");
+ BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
+ bonitaAuthFilter.filter(requestContext);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterConnectionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterConnectionTest.java b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterConnectionTest.java
new file mode 100644
index 0000000..7781d716
--- /dev/null
+++ b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterConnectionTest.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.bonita.api;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+
+import java.util.HashMap;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MultivaluedHashMap;
+
+import org.apache.camel.component.bonita.api.filter.BonitaAuthFilter;
+import org.apache.camel.component.bonita.api.util.BonitaAPIConfig;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.modules.junit4.PowerMockRunner;
+import static org.junit.Assert.*;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.net.ssl.*")
+public class BonitaAuthFilterConnectionTest {
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(0);
+
+ @Mock
+ private ClientRequestContext requestContext;
+
+ @Before
+ public void setup() {
+ Mockito.when(requestContext.getCookies()).thenReturn(new HashMap<String,Cookie>());
+ Mockito.when(requestContext.getHeaders()).thenReturn(new MultivaluedHashMap());
+ }
+
+ @Test
+ public void testConnection() throws Exception{
+ String port = wireMockRule.port() + "";
+ stubFor(post(urlEqualTo("/bonita/loginservice"))
+ .willReturn(aResponse()
+ .withHeader("Set-Cookie", "JSESSIONID=something")));
+
+ BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("localhost", port, "username", "password");
+ BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
+ bonitaAuthFilter.filter(requestContext);
+ assertEquals(1, requestContext.getHeaders().size());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterTest.java b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterTest.java
new file mode 100644
index 0000000..ad633cd
--- /dev/null
+++ b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/BonitaAuthFilterTest.java
@@ -0,0 +1,49 @@
+package org.apache.camel.component.bonita.api;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MultivaluedHashMap;
+
+import org.apache.camel.component.bonita.api.filter.BonitaAuthFilter;
+import org.apache.camel.component.bonita.api.util.BonitaAPIConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class BonitaAuthFilterTest {
+
+ @Mock
+ private ClientRequestContext requestContext;
+
+ @Before
+ public void setup() {
+ Map<String,Cookie> resultCookies = new HashMap<>();
+ Mockito.when(requestContext.getCookies()).thenReturn(resultCookies);
+
+ }
+
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testBonitaAuthFilterUsernameEmpty() throws IOException {
+ BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("localhost", "port", "", "password");
+ BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
+ bonitaAuthFilter.filter(requestContext);
+
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testBonitaAuthFilterPasswordEmpty() throws IOException {
+ BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("localhost", "port", "username", "");
+ BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
+ bonitaAuthFilter.filter(requestContext);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIConfigTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIConfigTest.java b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIConfigTest.java
new file mode 100644
index 0000000..8e26c0d
--- /dev/null
+++ b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIConfigTest.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.bonita.api.util;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.camel.component.bonita.api.util.BonitaAPIConfig;
+
+public class BonitaAPIConfigTest {
+
+ @Test
+ public void testBaseBonitaURL() {
+ BonitaAPIConfig config = new BonitaAPIConfig("host", "port", "username", "password");
+ assertEquals("http://host:port/bonita", config.getBaseBonitaURI());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIUtilPrepareInputsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIUtilPrepareInputsTest.java b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIUtilPrepareInputsTest.java
new file mode 100644
index 0000000..074f50b
--- /dev/null
+++ b/components/camel-bonita/src/test/java/org/apache/camel/component/bonita/api/util/BonitaAPIUtilPrepareInputsTest.java
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.bonita.api.util;
+
+import static org.junit.Assert.*;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.component.bonita.api.model.FileInput;
+import org.apache.camel.component.bonita.api.model.ProcessDefinitionResponse;
+import org.apache.camel.component.bonita.api.model.UploadFileResponse;
+import org.apache.camel.component.bonita.api.util.BonitaAPIConfig;
+import org.apache.camel.component.bonita.api.util.BonitaAPIUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(BonitaAPIUtil.class)
+public class BonitaAPIUtilPrepareInputsTest {
+
+
+ private BonitaAPIUtil bonitaApiUtil;
+
+ @Mock
+ ProcessDefinitionResponse processDefinition;
+
+ @Before
+ public void setup() {
+ bonitaApiUtil = BonitaAPIUtil.getInstance(new BonitaAPIConfig("hostname", "port", "username", "password"));
+ Mockito.when(processDefinition.getName()).thenReturn("processName");
+ Mockito.when(processDefinition.getVersion()).thenReturn("1.0");
+ Mockito.when(processDefinition.getId()).thenReturn("1");
+ }
+
+ @Test
+ public void testPrepareInputsEmpty() {
+ Map<String, Serializable> rawInputs = new HashMap<String,Serializable>();
+ Map<String, Serializable> inputs = bonitaApiUtil.prepareInputs(processDefinition, rawInputs);
+ assertEquals(inputs.size(), rawInputs.size());
+ }
+
+ @Test
+ public void testPrepareInputsNoFiles() {
+ Map<String, Serializable> rawInputs = new HashMap<String,Serializable>();
+ rawInputs.put("myVariable", 1);
+ Map<String, Serializable> inputs = bonitaApiUtil.prepareInputs(processDefinition, rawInputs);
+ assertEquals(rawInputs.size(), inputs.size());
+ }
+
+ @Test
+ public void testPrepareInputsOneFile() {
+
+ 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(Mockito.any(),Mockito.any());
+ Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
+ assertEquals(rawInputs.size(), inputs.size());
+ }
+
+ @Test
+ public void testPrepareInputsFileType() {
+
+ 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(Mockito.any(),Mockito.any());
+ Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
+ assertTrue(Map.class.isInstance(inputs.get("filename")));
+ }
+
+ @Test
+ public void testPrepareInputsTempFilePath() {
+
+ 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(Mockito.any(),Mockito.any());
+ Map<String, Serializable> inputs = bonitaApiUtilMod.prepareInputs(processDefinition, rawInputs);
+ Map<String, Serializable> fileMap = (Map<String, Serializable>)inputs.get("filename");
+ assertEquals("temp", fileMap.get("tempPath"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/camel-bonita/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-bonita/src/test/resources/log4j.properties b/components/camel-bonita/src/test/resources/log4j.properties
new file mode 100644
index 0000000..23a8d97
--- /dev/null
+++ b/components/camel-bonita/src/test/resources/log4j.properties
@@ -0,0 +1,29 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
http://git-wip-us.apache.org/repos/asf/camel/blob/0b057b16/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index e08c6ef..abbeb0b 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -75,6 +75,7 @@
<module>camel-bean-validator</module>
<module>camel-barcode</module>
<module>camel-bindy</module>
+ <module>camel-bonita</module>
<module>camel-boon</module>
<module>camel-box</module>
<module>camel-braintree</module>