Updated Branches: refs/heads/master 81377b0f8 -> 124c0e344
http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java ---------------------------------------------------------------------- diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java new file mode 100644 index 0000000..0cdc15f --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java @@ -0,0 +1,132 @@ +package org.apache.camel.component.facebook.data; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.*; +import org.apache.camel.component.facebook.config.FacebookEndpointConfiguration; +import org.junit.Test; + +import facebook4j.Facebook; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test {@link FacebookMethodsTypeHelper}. + */ +public class FacebookMethodsTypeHelperTest { + + private Set<String> names = new HashSet<String>(); + private final List<String> getExcludes; + private final List<String> searchIncludes; + + public FacebookMethodsTypeHelperTest() { + // get all method names + for (Class<?> aClass : Facebook.class.getInterfaces()) { + if (aClass.getName().endsWith("Methods")) { + for (Method method : aClass.getDeclaredMethods()) { + names.add(getShortName(method.getName())); + } + } + } + + getExcludes = Arrays.asList("places"); + searchIncludes = Arrays.asList("checkins", "events", "groups", "locations", "places", "posts", "users"); + } + + private String getShortName(String name) { + if (name.startsWith("get")) { + name = Character.toLowerCase(name.charAt(3)) + name.substring(4); + } else if (name.startsWith("search") && !"search".equals(name)) { + name = Character.toLowerCase(name.charAt(6)) + name.substring(7); + } + return name; + } + + @Test + public void testGetCandidateMethods() throws Exception { + for (FacebookMethodsType method : FacebookMethodsType.values()) { + final String name = method.getName(); + final String shortName = getShortName(method.getName()); + + final String[] argNames = method.getArgNames().toArray(new String[method.getArgNames().size()]); + List<FacebookMethodsType> candidates = FacebookMethodsTypeHelper.getCandidateMethods(name, argNames); + assertFalse("No candidate methods for " + name, candidates.isEmpty()); + + if (!name.equals(shortName) && !"search".equals(name)) { + if (!getExcludes.contains(shortName)) { + candidates = FacebookMethodsTypeHelper.getCandidateMethods( + FacebookMethodsTypeHelper.convertToGetMethod(shortName), new String[0]); + assertFalse("No candidate get methods for " + shortName, candidates.isEmpty()); + } + + if (searchIncludes.contains(shortName)) { + candidates = FacebookMethodsTypeHelper.getCandidateMethods( + FacebookMethodsTypeHelper.convertToSearchMethod(shortName), new String[0]); + assertFalse("No candidate search methods for " + shortName, candidates.isEmpty()); + } + } + } + } + + @Test + public void testFilterMethods() throws Exception { + // TODO + } + + @Test + public void testGetArguments() throws Exception { + final Class<?>[] interfaces = Facebook.class.getInterfaces(); + for (Class clazz : interfaces) { + if (clazz.getName().endsWith("Methods")) { + // check all methods of this *Methods interface + for (Method method : clazz.getDeclaredMethods()) { + // will throw an exception if can't be found + final List<Object> arguments = FacebookMethodsTypeHelper.getArguments(method.getName()); + final int nArgs = arguments.size() / 2; + List<Class> types = new ArrayList<Class>(nArgs); + for (int i = 0; i < nArgs; i++) { + types.add((Class) arguments.get(2 * i)); + } + assertTrue("Missing parameters for " + method, + types.containsAll(Arrays.asList(method.getParameterTypes()))); + } + } + } + } + + @Test + public void testAllArguments() throws Exception { + assertFalse("Missing arguments", FacebookMethodsTypeHelper.allArguments().isEmpty()); + } + + @Test + public void testGetType() throws Exception { + for (Field field : FacebookEndpointConfiguration.class.getDeclaredFields()) { + Class expectedType = field.getType(); + final Class actualType = FacebookMethodsTypeHelper.getType(field.getName()); + // test for auto boxing, un-boxing + if (actualType.isPrimitive()) { + expectedType = (Class) expectedType.getField("TYPE").get(null); + } else if (List.class.isAssignableFrom(expectedType) && actualType.isArray()) { + // skip lists, since they will be converted in invokeMethod() + expectedType = actualType; + } + assertEquals("Missing property " + field.getName(), expectedType, actualType); + } + } + + @Test + public void testConvertToGetMethod() throws Exception { + assertEquals("Invalid get method name", + FacebookMethodsType.GET_ACCOUNTS.getName(), FacebookMethodsTypeHelper.convertToGetMethod("accounts")); + } + + @Test + public void testConvertToSearchMethod() throws Exception { + assertEquals("Invalid search method name", + FacebookMethodsType.SEARCHPOSTS.getName(), FacebookMethodsTypeHelper.convertToSearchMethod("posts")); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java new file mode 100644 index 0000000..1f390e4 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java @@ -0,0 +1,47 @@ +/** + * 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.facebook.data; + +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import facebook4j.Facebook; +import org.junit.Test; + +/** + * Test that all *Methods methods are mapped in {@link FacebookMethodsType}. + */ +public class FacebookMethodsTypeTest { + + @Test + public void areAllMethodsMapped() throws Exception { + final Class<?>[] interfaces = Facebook.class.getInterfaces(); + for (Class clazz : interfaces) { + if (clazz.getName().endsWith("Methods")) { + // check all methods of this *Methods interface + for (Method method : clazz.getDeclaredMethods()) { + final FacebookMethodsType methodsType = FacebookMethodsType.findMethod(method.getName(), method.getParameterTypes()); + assertNotNull(methodsType); + assertEquals("Methods are not equal", method, methodsType.getMethod()); + } + } + } + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/ReadingBuilderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/ReadingBuilderTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/ReadingBuilderTest.java new file mode 100644 index 0000000..e58d0d7 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/ReadingBuilderTest.java @@ -0,0 +1,63 @@ +package org.apache.camel.component.facebook.data; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import static org.junit.Assert.*; + +import facebook4j.Reading; +import org.apache.camel.component.facebook.FacebookConstants; +import org.junit.Test; + +/** + * Test {@link ReadingBuilder}. + */ +public class ReadingBuilderTest { + + @Test + public void testCopy() throws Exception { + final Reading source = new Reading(); + source.fields("field1", "field2"); + source.filter("testFilter"); + source.limit(100); + source.locale(Locale.US); + source.metadata(); + source.offset(1000); + source.since(new Date()); + source.until(new Date()); + source.withLocation(); + + Reading copy = ReadingBuilder.copy(source, false); + assertNotNull("Null copy", copy); + assertEquals("Copy not equal", source.toString(), copy.toString()); + + // skip since and until + copy = ReadingBuilder.copy(source, true); + assertNotEquals("Copy equal", source.toString(), copy.toString()); + assertFalse("since", copy.toString().contains("since=")); + assertFalse("until", copy.toString().contains("until=")); + } + + @Test + public void testSetProperties() throws Exception { + final Reading reading = new Reading(); + + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put("fields", "field1,field2"); + properties.put("filter", "testFilter"); + properties.put("limit", "100"); + properties.put("metadata", ""); + properties.put("offset", "1000"); + final String facebookDate = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT).format(new Date()); + properties.put("since", facebookDate); + properties.put("until", facebookDate); + properties.put("withLocation", ""); + + // set properties on Reading + ReadingBuilder.setProperties(reading, properties); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/components/camel-facebook/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-facebook/src/test/resources/log4j.properties b/components/camel-facebook/src/test/resources/log4j.properties new file mode 100644 index 0000000..f4153d6 --- /dev/null +++ b/components/camel-facebook/src/test/resources/log4j.properties @@ -0,0 +1,31 @@ +## --------------------------------------------------------------------------- +## 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 during tests.. +# +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/1c293408/components/camel-facebook/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-facebook/src/test/resources/test-options.properties b/components/camel-facebook/src/test/resources/test-options.properties new file mode 100644 index 0000000..ab2a99f --- /dev/null +++ b/components/camel-facebook/src/test/resources/test-options.properties @@ -0,0 +1,20 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +oAuthAppId=<app-id> +oAuthAppSecret=<app-secret> +oAuthAccessToken=<access-token> http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 89b981b..811c702 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -81,6 +81,7 @@ <module>camel-elasticsearch</module> <module>camel-eventadmin</module> <module>camel-exec</module> + <module>camel-facebook</module> <module>camel-flatpack</module> <module>camel-fop</module> <module>camel-freemarker</module> @@ -239,4 +240,4 @@ </dependencies> </profile> </profiles> -</project> +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 83e9684..9d1ab48 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -124,6 +124,7 @@ <el-api-1.0-version>1.0.1</el-api-1.0-version> <exec-maven-plugin-version>1.2.1</exec-maven-plugin-version> <ezmorph-bundle-version>1.0.6_1</ezmorph-bundle-version> + <facebook4j-core-version>1.1.12</facebook4j-core-version> <fastinfoset-version>1.2.13_1</fastinfoset-version> <felix-configadmin-version>1.4.0</felix-configadmin-version> <felix-fileinstall-version>3.2.6</felix-fileinstall-version> http://git-wip-us.apache.org/repos/asf/camel/blob/1c293408/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index 4e18ca0..8e67404 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -269,6 +269,11 @@ <bundle dependency='true'>mvn:commons-io/commons-io/${commons-io-version}</bundle> <bundle>mvn:org.apache.camel/camel-exec/${project.version}</bundle> </feature> + <feature name='camel-facebook' version='${project.version}' resolver='(obr)' start-level='50'> + <feature version='${project.version}'>camel-core</feature> + <bundle dependency='true'>wrap:mvn:org.facebook4j/facebook4j-core/${facebook4j-core-version}</bundle> + <bundle>mvn:org.apache.camel/camel-facebook/${project.version}</bundle> + </feature> <feature name='camel-flatpack' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${project.version}'>camel-core</feature> <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jdom/${jdom-bundle-version}</bundle>