Fixed test and polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c8ca2d3d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c8ca2d3d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c8ca2d3d Branch: refs/heads/master Commit: c8ca2d3d10fa26dcf3cf55262c404571bbedffcd Parents: 8542bb2 Author: Claus Ibsen <davscl...@apache.org> Authored: Sat Aug 20 11:19:23 2016 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat Aug 20 11:19:23 2016 +0200 ---------------------------------------------------------------------- components/camel-gora/pom.xml | 355 +++++++++---------- .../camel/component/gora/utils/GoraUtils.java | 73 ---- .../component/gora/GoraConfigurationTest.java | 11 +- .../camel/component/gora/GoraConsumerTest.java | 8 - .../camel/component/gora/GoraProducerTest.java | 88 +---- .../camel/component/gora/GoraTestSupport.java | 3 +- .../component/gora/utils/GoraUtilsTest.java | 5 - 7 files changed, 174 insertions(+), 369 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-gora/pom.xml b/components/camel-gora/pom.xml index 3a12d7c..db951bb 100644 --- a/components/camel-gora/pom.xml +++ b/components/camel-gora/pom.xml @@ -1,191 +1,170 @@ +<?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 2011 Ioannis Polyzos - - Licensed 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>2.18-SNAPSHOT</version> - </parent> - - <artifactId>camel-gora</artifactId> - <packaging>jar</packaging> - <name>Camel :: Gora</name> - - <description> - Gora Component for Apache Camel. - </description> - - <properties> - <camel.osgi.export.pkg> - org.apache.camel.component.gora.* - </camel.osgi.export.pkg> - <camel.osgi.import.before.defaults> - org.apache.camel.* - com.google.common.base;version="[11,14)", - org.apache.hadoop.conf;version="[1,2)" - </camel.osgi.import.before.defaults> - <camel.osgi.export.pkg>org.apache.camel.component.gora.*</camel.osgi.export.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=gora</camel.osgi.export.service> - - </properties> - - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <org.slf4j.simpleLogger.defaultLogLevel> - warn - </org.slf4j.simpleLogger.defaultLogLevel> - </systemPropertyVariables> - </configuration> - </plugin> - </plugins> - </build> - - <dependencies> - <!-- logging --> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <scope>test</scope> - </dependency> - - <!-- testing --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>${mockito-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-core</artifactId> - <version>${powermock-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>${powermock-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <version>${powermock-version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> - <scope>test</scope> - </dependency> - - <!-- apache camel --> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - </dependency> - - <!-- apache gora --> - <dependency> - <groupId>org.apache.gora</groupId> - <artifactId>gora-core</artifactId> - <version>${apache-gora-version}</version> - <exclusions> - <!-- because we have a direct dependency to org.apache.servicemix.bundles:org.apache.servicemix.bundles.hadoop-core --> - <exclusion> - <groupId>org.apache.hadoop</groupId> - <artifactId>hadoop-core</artifactId> - </exclusion> - </exclusions> - </dependency> - - <!-- hadoop --> - <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId>org.apache.servicemix.bundles.hadoop-core</artifactId> - <version>${hadoop-bundle-version}</version> - <exclusions> - <exclusion> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils-core</artifactId> - </exclusion> - </exclusions> - </dependency> - - <!-- Avro --> - <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId>org.apache.servicemix.bundles.avro</artifactId> - <version>${avro-bundle-version}</version> - </dependency> - - <!-- other --> - <!-- Avro needs this version of jackson --> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-core-asl</artifactId> - <version>${jackson-version}</version> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-asl</artifactId> - <version>${jackson-version}</version> - </dependency> - <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId>org.apache.servicemix.bundles.jdom</artifactId> - <version>${jdom-bundle-version}</version> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>${google-guava-version}</version> - </dependency> - <dependency> - <groupId>org.apache.servicemix.bundles</groupId> - <artifactId>org.apache.servicemix.bundles.commons-beanutils</artifactId> - <version>${commons-beanutils-bundle-version}</version> - </dependency> - </dependencies> + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.18-SNAPSHOT</version> + </parent> + + <artifactId>camel-gora</artifactId> + <packaging>jar</packaging> + <name>Camel :: Gora</name> + <description>Gora Component for Apache Camel.</description> + + <properties> + <camel.osgi.export.pkg> + org.apache.camel.component.gora.* + </camel.osgi.export.pkg> + <camel.osgi.import.before.defaults> + org.apache.camel.* + com.google.common.base;version="[11,14)", + org.apache.hadoop.conf;version="[1,2)" + </camel.osgi.import.before.defaults> + <camel.osgi.export.pkg>org.apache.camel.component.gora.*</camel.osgi.export.pkg> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=gora</camel.osgi.export.service> + </properties> + + <dependencies> + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>${mockito-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + + <!-- apache camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + + <!-- apache gora --> + <dependency> + <groupId>org.apache.gora</groupId> + <artifactId>gora-core</artifactId> + <version>${apache-gora-version}</version> + <exclusions> + <!-- because we have a direct dependency to org.apache.servicemix.bundles:org.apache.servicemix.bundles.hadoop-core --> + <exclusion> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-core</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- hadoop --> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.hadoop-core</artifactId> + <version>${hadoop-bundle-version}</version> + <exclusions> + <exclusion> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils-core</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- Avro --> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.avro</artifactId> + <version>${avro-bundle-version}</version> + </dependency> + + <!-- other --> + <!-- Avro needs this version of jackson --> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-core-asl</artifactId> + <version>${jackson-version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>${jackson-version}</version> + </dependency> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.jdom</artifactId> + <version>${jdom-bundle-version}</version> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>${google-guava-version}</version> + </dependency> + <dependency> + <groupId>org.apache.servicemix.bundles</groupId> + <artifactId>org.apache.servicemix.bundles.commons-beanutils</artifactId> + <version>${commons-beanutils-bundle-version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <systemPropertyVariables> + <org.slf4j.simpleLogger.defaultLogLevel>warn</org.slf4j.simpleLogger.defaultLogLevel> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/main/java/org/apache/camel/component/gora/utils/GoraUtils.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/utils/GoraUtils.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/utils/GoraUtils.java index 4660507..d9f17d2 100644 --- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/utils/GoraUtils.java +++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/utils/GoraUtils.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.gora.utils; import java.lang.reflect.InvocationTargetException; @@ -33,7 +32,6 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * GoraUtil class contain utility methods for the * camel component. - * */ public final class GoraUtils { @@ -42,7 +40,6 @@ public final class GoraUtils { * instantiation of the class. */ private GoraUtils() { - // utility Class } @@ -51,14 +48,6 @@ public final class GoraUtils { * * <b>NOTE:</b> values used in order construct the query * should be stored in the "in" message headers. - * - * @param dataStore - * @param conf - * @return - * @throws ClassNotFoundException - * @throws IllegalAccessException - * @throws NoSuchMethodException - * @throws InvocationTargetException */ public static Query<Object, Persistent> constractQueryFromConfiguration(final DataStore<Object, Persistent> dataStore, final GoraConfiguration conf) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { @@ -109,18 +98,11 @@ public final class GoraUtils { * * <b>NOTE:</b> values used in order construct the query * should be stored in the "in" message headers. - * - * @param propertiesMap - * @param dataStore - * @param conf - * @return - * @throws ClassNotFoundException */ public static Query<Object, Persistent> constractQueryFromPropertiesMap(final Map<String, ?> propertiesMap, final DataStore<Object, Persistent> dataStore, final GoraConfiguration conf) throws ClassNotFoundException { - final Query<Object, Persistent> query = dataStore.newQuery(); if (propertyExist(GoraAttribute.GORA_QUERY_START_TIME, propertiesMap)) { @@ -167,119 +149,67 @@ public final class GoraUtils { * * <b>NOTE:</> * Checks only if is not null - * - * @param attr - * @param conf - * @return - * @throws IllegalAccessException - * @throws NoSuchMethodException - * @throws InvocationTargetException */ protected static boolean configurationExist(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - return PropertyUtils.getSimpleProperty(conf, attr.value) != null; } /** * Utility method to check if a value exist in the properties map - * - * @param attr - * @param propertiesMap - * @return */ protected static boolean propertyExist(final GoraAttribute attr, final Map<String, ?> propertiesMap) { - return propertiesMap.containsKey(attr.value); } /** * Utility method to extract value from configuration - * - * @param attr - * @param conf - * @return - * @throws IllegalAccessException - * @throws NoSuchMethodException - * @throws InvocationTargetException */ protected static Object getAttribute(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - return PropertyUtils.getSimpleProperty(conf, attr.value); } /** * Utility method to extract value from configuration as String - * - * @param attr - * @param conf - * @return - * @throws IllegalAccessException - * @throws NoSuchMethodException - * @throws InvocationTargetException */ protected static String getAttributeAsString(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - return String.valueOf(getAttribute(attr, conf)); } /** * Utility method to extract value from configuration as Long - * - * @param attr - * @param conf - * @return - * @throws IllegalAccessException - * @throws NoSuchMethodException - * @throws InvocationTargetException */ protected static Long getAttributeAsLong(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { - return Long.parseLong(getAttributeAsString(attr, conf)); } /** * Utility method to extract value of a map - * - * @param attr - * @param propertiesMap - * @return */ protected static Object getProperty(final GoraAttribute attr, final Map<String, ?> propertiesMap) { - return propertiesMap.get(attr.value); } /** * Utility method to extract value of a map as String - * - * @param attr - * @param propertiesMap - * @return */ protected static String getPropertyAsString(final GoraAttribute attr, final Map<String, ?> propertiesMap) { - return String.valueOf(getProperty(attr, propertiesMap)); } /** * Utility method to extract value of a map as long - * - * @param attr - * @param propertiesMap - * @return */ protected static Long getPropertyAsLong(final GoraAttribute attr, final Map<String, ?> propertiesMap) { - return Long.parseLong(getPropertyAsString(attr, propertiesMap)); } @@ -294,9 +224,7 @@ public final class GoraUtils { * @return The key */ public static Object getKeyFromExchange(Exchange exchange) { - final Object key = exchange.getIn().getHeader(GoraAttribute.GORA_KEY.value); - checkNotNull(key, "Key should not be null!"); return key; } @@ -311,7 +239,6 @@ public final class GoraUtils { * @return The value */ public static Persistent getValueFromExchange(Exchange exchange) { - return exchange.getIn().getBody(Persistent.class); } http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java index ef20e31..106b100 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConfigurationTest.java @@ -14,64 +14,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.gora; import org.junit.Test; /** * GORA Configuration Tests - * */ public class GoraConfigurationTest { - @Test(expected = IllegalArgumentException.class) public void setKeyClassClassShouldThrowExceptionIfNull() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setValueClass(null); } @Test(expected = IllegalArgumentException.class) public void setKeyClassShouldThrowExceptionIfEmpty() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setValueClass(""); } @Test(expected = IllegalArgumentException.class) public void setValueClassClassShouldThrowExceptionIfNull() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setValueClass(null); } @Test(expected = IllegalArgumentException.class) public void setValueClassClassShouldThrowExceptionIfEmpty() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setValueClass(""); } @Test(expected = IllegalArgumentException.class) public void setDataStoreClassShouldThrowExceptionIfNull() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setDataStoreClass(null); } @Test(expected = IllegalArgumentException.class) public void setDataStoreClassShouldThrowExceptionIfEmpty() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setDataStoreClass(""); } @Test(expected = NullPointerException.class) public void setHadoopConfigurationShouldThrowExceptionIfNull() { - final GoraConfiguration conf = new GoraConfiguration(); conf.setHadoopConfiguration(null); } + } http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java index f2d22b0..a00f865 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraConsumerTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.gora; import java.lang.reflect.InvocationTargetException; @@ -33,7 +32,6 @@ import static org.mockito.Mockito.when; /** * GORA Consumer Tests - * */ public class GoraConsumerTest extends GoraTestSupport { @@ -67,28 +65,22 @@ public class GoraConsumerTest extends GoraTestSupport { */ private Processor mockGoraProcessor; - @Before public void setUp() { - //setup mocks mockCamelExchange = mock(Exchange.class); mockGoraEndpoint = mock(GoraEndpoint.class); mockGoraConfiguration = mock(GoraConfiguration.class); mockCamelMessage = mock(Message.class); mockDatastore = mock(DataStore.class); - //setup default conditions when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelExchange.getPattern()).thenReturn(ExchangePattern.InOnly); } - @Test public void consumerInstantiationWithMocksShouldSucceed() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - - final Query mockQuery = mock(Query.class); when(mockDatastore.newQuery()).thenReturn(mockQuery); GoraConsumer goraConsumer = new GoraConsumer(mockGoraEndpoint, mockGoraProcessor, mockGoraConfiguration, mockDatastore); http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java index 4012e82..4fd7203 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraProducerTest.java @@ -14,44 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.gora; -import java.util.Map; - import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.Message; -import org.apache.camel.component.gora.utils.GoraUtils; import org.apache.gora.persistency.Persistent; -import org.apache.gora.query.Query; -import org.apache.gora.query.impl.QueryBase; import org.apache.gora.store.DataStore; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atMost; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.verifyStatic; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.when; /** * GORA Producer Tests - * - * TODO: <b>NOTE:</b> Query methods does not yet has tests - * */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(GoraUtils.class) public class GoraProducerTest extends GoraTestSupport { + // TODO: Query methods does not yet has tests + /** * Mock CamelExchange */ @@ -79,7 +64,6 @@ public class GoraProducerTest extends GoraTestSupport { @Before public void setUp() { - //setup mocks mockCamelExchange = mock(Exchange.class); mockGoraEndpoint = mock(GoraEndpoint.class); @@ -94,15 +78,12 @@ public class GoraProducerTest extends GoraTestSupport { @Test(expected = RuntimeException.class) public void processShouldThrowExceptionIfOperationIsNull() throws Exception { - final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore); producer.process(mockCamelExchange); } @Test(expected = RuntimeException.class) public void shouldThrowExceptionIfOperationIsUnknown() throws Exception { - - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("dah"); @@ -115,7 +96,6 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDastorePut() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("PUT"); @@ -140,7 +120,6 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDastoreGet() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("get"); @@ -161,7 +140,6 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDatastoreDelete() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("dEletE"); @@ -182,7 +160,6 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDastoreSchemaExists() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("schemaExists"); @@ -199,7 +176,6 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDastoreCreateSchema() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("createSchema"); @@ -216,11 +192,9 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDastoreGetSchemaName() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("GetSchemANamE"); - final Message outMessage = mock(Message.class); when(mockCamelExchange.getOut()).thenReturn(outMessage); @@ -234,11 +208,9 @@ public class GoraProducerTest extends GoraTestSupport { @Test public void shouldInvokeDatastoreDeleteSchema() throws Exception { - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("DeleteSChEmA"); - final Message outMessage = mock(Message.class); when(mockCamelExchange.getOut()).thenReturn(outMessage); @@ -250,56 +222,4 @@ public class GoraProducerTest extends GoraTestSupport { verify(mockDatastore, atMost(1)).deleteSchema(); } - @Test - public void shouldInvokeDatastoreQuery() throws Exception { - - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); - when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("query"); - - final Map<String, Object> mockProperties = mock(Map.class); - when(mockCamelMessage.getHeaders()).thenReturn(mockProperties); - - final Message outMessage = mock(Message.class); - when(mockCamelExchange.getOut()).thenReturn(outMessage); - - mockStatic(GoraUtils.class); - - final Query mockQuery = mock(QueryBase.class); - when(GoraUtils.constractQueryFromPropertiesMap(mockProperties, mockDatastore, mockGoraConfiguration)).thenReturn(mockQuery); - - final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore); - producer.process(mockCamelExchange); - - verify(mockCamelExchange, atLeastOnce()).getIn(); - verify(mockCamelMessage, atLeastOnce()).getHeader(GoraAttribute.GORA_OPERATION.value); - verify(mockQuery, atLeastOnce()).execute(); - verifyStatic(times(1)); - } - - @Test - public void shouldInvokeDatastoreDeleteByQuery() throws Exception { - - when(mockCamelExchange.getIn()).thenReturn(mockCamelMessage); - when(mockCamelMessage.getHeader(GoraAttribute.GORA_OPERATION.value)).thenReturn("deleteByQuery"); - - final Map<String, Object> mockProperties = mock(Map.class); - when(mockCamelMessage.getHeaders()).thenReturn(mockProperties); - - final Message outMessage = mock(Message.class); - when(mockCamelExchange.getOut()).thenReturn(outMessage); - - mockStatic(GoraUtils.class); - - final Query mockQuery = mock(QueryBase.class); - when(GoraUtils.constractQueryFromPropertiesMap(mockProperties, mockDatastore, mockGoraConfiguration)).thenReturn(mockQuery); - - final GoraProducer producer = new GoraProducer(mockGoraEndpoint, mockGoraConfiguration, mockDatastore); - producer.process(mockCamelExchange); - - verify(mockCamelExchange, atLeastOnce()).getIn(); - verify(mockCamelMessage, atLeastOnce()).getHeader(GoraAttribute.GORA_OPERATION.value); - verify(mockDatastore, atMost(1)).deleteByQuery(mockQuery); - verifyStatic(times(1)); - } - } http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java index 3d11e80..006fee3 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/GoraTestSupport.java @@ -24,5 +24,6 @@ import org.apache.camel.test.junit4.CamelTestSupport; * */ public class GoraTestSupport extends CamelTestSupport { - //TODO + + // currently empty } http://git-wip-us.apache.org/repos/asf/camel/blob/c8ca2d3d/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java b/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java index 56ecfb4..0a36b63 100644 --- a/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java +++ b/components/camel-gora/src/test/java/org/apache/camel/component/gora/utils/GoraUtilsTest.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.camel.component.gora.utils; import org.apache.camel.component.gora.GoraAttribute; @@ -26,27 +25,23 @@ import static org.junit.Assert.assertTrue; /** * GORA Utils Tests - * */ public class GoraUtilsTest { @Test public void configurationExistShouldSucceedtIfMethodExist() throws Exception { - final GoraConfiguration conf = new GoraConfiguration(); assertTrue(GoraUtils.configurationExist(GoraAttribute.GORA_QUERY_LIMIT, conf)); } @Test(expected = NoSuchMethodException.class) public void configurationExistShouldThrowExceptionIfMethodDoesNotExist() throws Exception { - final GoraConfiguration conf = new GoraConfiguration(); GoraUtils.configurationExist(GoraAttribute.GORA_KEY, conf); } @Test public void getAttributeAsLongShouldSReturnTheCorrectValue() throws Exception { - final GoraConfiguration conf = new GoraConfiguration(); conf.setLimit(3L); assertEquals(new Long(3), GoraUtils.getAttributeAsLong(GoraAttribute.GORA_QUERY_LIMIT, conf));