You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/04/18 11:45:10 UTC
cxf git commit: [CXF-7329] Adding @Validated to CxfProperties,
modified patch from Fred Assi applied, This closes #261
Repository: cxf
Updated Branches:
refs/heads/master da8ed20b1 -> 931ee8103
[CXF-7329] Adding @Validated to CxfProperties, modified patch from Fred Assi applied, This closes #261
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/931ee810
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/931ee810
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/931ee810
Branch: refs/heads/master
Commit: 931ee8103f7762e8e96a3ae7fb329defb18d68aa
Parents: da8ed20
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Tue Apr 18 12:44:54 2017 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Tue Apr 18 12:44:54 2017 +0100
----------------------------------------------------------------------
integration/spring-boot/autoconfigure/pom.xml | 22 +++++
.../boot/autoconfigure/CxfProperties.java | 6 +-
.../boot/autoconfigure/CxfPropertiesTest.java | 86 ++++++++++++++++++++
3 files changed, 112 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/931ee810/integration/spring-boot/autoconfigure/pom.xml
----------------------------------------------------------------------
diff --git a/integration/spring-boot/autoconfigure/pom.xml b/integration/spring-boot/autoconfigure/pom.xml
index 0a44f7c..16eb333 100644
--- a/integration/spring-boot/autoconfigure/pom.xml
+++ b/integration/spring-boot/autoconfigure/pom.xml
@@ -110,5 +110,27 @@
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${cxf.slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${cxf.logback.classic.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <version>${cxf.javax.el.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>${cxf.hibernate.validator.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/931ee810/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/CxfProperties.java
----------------------------------------------------------------------
diff --git a/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/CxfProperties.java b/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/CxfProperties.java
index 14dff82..a745d75 100644
--- a/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/CxfProperties.java
+++ b/integration/spring-boot/autoconfigure/src/main/java/org/apache/cxf/spring/boot/autoconfigure/CxfProperties.java
@@ -25,6 +25,7 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
/**
* {@link ConfigurationProperties} for Apache CXF.
@@ -32,17 +33,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Vedran Pavic
*/
@ConfigurationProperties("cxf")
+@Validated
public class CxfProperties {
/**
* Path that serves as the base URI for the services.
*/
- @NotNull
- @Pattern(regexp = "/[^?#]*", message = "Path must start with /")
private String path = "/services";
private final Servlet servlet = new Servlet();
+ @NotNull
+ @Pattern(regexp = "/[^?#]*", message = "Path must start with /")
public String getPath() {
return this.path;
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/931ee810/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfPropertiesTest.java
----------------------------------------------------------------------
diff --git a/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfPropertiesTest.java b/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfPropertiesTest.java
new file mode 100644
index 0000000..b38b819
--- /dev/null
+++ b/integration/spring-boot/autoconfigure/src/test/java/org/apache/cxf/spring/boot/autoconfigure/CxfPropertiesTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.cxf.spring.boot.autoconfigure;
+
+import javax.validation.ConstraintViolationException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
+
+@ContextConfiguration(classes = {CxfPropertiesTest.Config.class})
+@RunWith(SpringJUnit4ClassRunner.class)
+public class CxfPropertiesTest extends Assert {
+
+ @Configuration
+ public static class Config {
+ @Bean
+ public MethodValidationPostProcessor methodValidationPostProcessor() {
+ return new MethodValidationPostProcessor();
+ }
+
+ @Bean
+ public CxfProperties cxfProperties() {
+ return new CxfProperties();
+ }
+ }
+
+ @Autowired
+ private CxfProperties cxfproperties;
+
+ @Test
+ public void throwsViolationExceptionWhenIsNull() {
+ doTestInvalidPath(null);
+ }
+
+ @Test
+ public void throwsViolationExceptionWhenPathIsEmpty() {
+ doTestInvalidPath("");
+ }
+
+ @Test
+ public void throwsViolationExceptionWhenHasNoSlash() {
+ doTestInvalidPath("invalid");
+ }
+
+ private void doTestInvalidPath(String value) {
+ cxfproperties.setPath(value);
+ try {
+ cxfproperties.getPath();
+ fail("ConstraintViolationException is expected");
+ } catch (ConstraintViolationException e) {
+ assertEquals(1, e.getConstraintViolations().size());
+ }
+ }
+
+ @Test
+ public void noViolationExceptionWhenPathValid() {
+ cxfproperties.setPath("/valid");
+ cxfproperties.getPath();
+ }
+
+}