camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject git commit: [CAMEL-7168] Provided OSGi-friendly ValidationProviderResolver.
Date Tue, 04 Feb 2014 14:46:18 GMT
Updated Branches:
  refs/heads/master 18bb3b673 -> 058d22e83


[CAMEL-7168] Provided OSGi-friendly ValidationProviderResolver.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/058d22e8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/058d22e8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/058d22e8

Branch: refs/heads/master
Commit: 058d22e83a9f9d343ebb7299ca8cf371c69135de
Parents: 18bb3b6
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Tue Feb 4 15:45:59 2014 +0100
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Tue Feb 4 15:45:59 2014 +0100

----------------------------------------------------------------------
 .../HibernateValidationProviderResolver.java    | 37 +++++++++++
 ...HibernateValidationProviderResolverTest.java | 69 ++++++++++++++++++++
 2 files changed, 106 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/058d22e8/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolver.java
b/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolver.java
new file mode 100644
index 0000000..78839fa
--- /dev/null
+++ b/components/camel-bean-validator/src/main/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolver.java
@@ -0,0 +1,37 @@
+/**
+ * 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.bean.validator;
+
+import java.util.List;
+
+import static java.util.Collections.singletonList;
+
+import javax.validation.ValidationProviderResolver;
+import org.hibernate.validator.HibernateValidator;
+
+/**
+ * OSGi-friendly implementation of {@code javax.validation.ValidationProviderResolver} returning
+ * {@code org.hibernate.validator.HibernateValidator} instance.
+ */
+public class HibernateValidationProviderResolver implements ValidationProviderResolver {
+
+    @Override
+    public List getValidationProviders() {
+        return singletonList(new HibernateValidator());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/058d22e8/components/camel-bean-validator/src/test/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolverTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bean-validator/src/test/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolverTest.java
b/components/camel-bean-validator/src/test/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolverTest.java
new file mode 100644
index 0000000..80f44e5
--- /dev/null
+++ b/components/camel-bean-validator/src/test/java/org/apache/camel/component/bean/validator/HibernateValidationProviderResolverTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.bean.validator;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class HibernateValidationProviderResolverTest extends CamelTestSupport {
+
+    // Routing fixtures
+
+    @EndpointInject(uri = "mock:test")
+    MockEndpoint mockEndpoint;
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(BeanValidationException.class).to(mockEndpoint);
+
+                from("direct:test").
+                    to("bean-validator://ValidationProviderResolverTest?validationProviderResolver=#myValidationProviderResolver");
+            }
+        };
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("myValidationProviderResolver", new HibernateValidationProviderResolver());
+        return registry;
+    }
+
+    // Tests
+
+    @Test
+    public void shouldResolveHibernateValidationProviderResolver() throws InterruptedException
{
+        // Given
+        mockEndpoint.expectedMessageCount(1);
+        mockEndpoint.message(0).body().isInstanceOf(CarWithAnnotations.class);
+        CarWithAnnotations carWithNullFields = new CarWithAnnotations(null, null);
+
+        // When
+        sendBody("direct:test", carWithNullFields);
+
+        // Then
+        assertMockEndpointsSatisfied();
+    }
+
+}


Mime
View raw message