-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve camel-quarkus-bean-validator test coverage #3567
- Loading branch information
1 parent
6fe10c5
commit dca226c
Showing
12 changed files
with
338 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
=== Configuring the ValidatorFactory | ||
|
||
Implementation of this extension leverages https://quarkus.io/guides/validation[Quarkus extension]. | ||
|
||
Therefore it is not possible to configure ValidatorFactory by Camel's properties ('constraintValidatorFactory`, `messageInterpolator`, `traversableResolver`, `validationProviderResolver` and `validatorFactory`). | ||
You can configure ValidatorFactory by creation of beans which will be injected into the default validatorFactory (created by Quarkus). | ||
See https://quarkus.io/guides/validation#hibernate-validator-extension-and-cdi[documentation] for more information. | ||
=== Custom validation groups in native mode | ||
For native mode, it is necessary to register definitions of custom validation groups for reflection. | ||
To do this, annotate interface definition with `@RegisterForReflection`. | ||
Example: | ||
[source,java] | ||
---- | ||
@RegisterForReflection | ||
public interface OptionalChecks { | ||
} | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...java/org/apache/camel/quarkus/component/bean/validator/it/ValidatinFactoryCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.camel.quarkus.component.bean.validator.it; | ||
|
||
import org.hibernate.validator.internal.constraintvalidators.bv.NotNullValidator; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorFactory; | ||
import javax.validation.MessageInterpolator; | ||
import javax.validation.Path; | ||
import javax.validation.TraversableResolver; | ||
import java.lang.annotation.ElementType; | ||
import java.util.Locale; | ||
|
||
@ApplicationScoped | ||
public class ValidatinFactoryCustomizer { | ||
|
||
@Produces | ||
@Singleton | ||
public MyMessageInterpolator createMyMessageInterpolator() { | ||
return new MyMessageInterpolator(); | ||
} | ||
|
||
class MyMessageInterpolator implements MessageInterpolator { | ||
|
||
private int count = 0; | ||
|
||
@Override | ||
public String interpolate(String messageTemplate, Context context) { | ||
count++; | ||
return null; | ||
} | ||
|
||
@Override | ||
public String interpolate(String messageTemplate, Context context, Locale locale) { | ||
count++; | ||
return null; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...n/java/org/apache/camel/quarkus/component/bean/validator/it/model/CarWithAnnotations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.quarkus.component.bean.validator.it.model; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
public class CarWithAnnotations implements Car { | ||
|
||
@NotNull | ||
private String manufacturer; | ||
|
||
@NotNull | ||
@Size(min = 5, max = 14) | ||
private String licensePlate; | ||
|
||
public CarWithAnnotations(String manufacturer, String licencePlate) { | ||
this.manufacturer = manufacturer; | ||
this.licensePlate = licencePlate; | ||
} | ||
|
||
@Override | ||
public String getManufacturer() { | ||
return manufacturer; | ||
} | ||
|
||
@Override | ||
public void setManufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
} | ||
|
||
@Override | ||
public String getLicensePlate() { | ||
return licensePlate; | ||
} | ||
|
||
@Override | ||
public void setLicensePlate(String licensePlate) { | ||
this.licensePlate = licensePlate; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ava/org/apache/camel/quarkus/component/bean/validator/it/model/CarWithoutAnnotations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.quarkus.component.bean.validator.it.model; | ||
|
||
//@RegisterForReflection | ||
public class CarWithoutAnnotations implements Car { | ||
|
||
private String manufacturer; | ||
|
||
private String licensePlate; | ||
|
||
public CarWithoutAnnotations(String manufacturer, String licencePlate) { | ||
this.manufacturer = manufacturer; | ||
this.licensePlate = licencePlate; | ||
} | ||
|
||
@Override | ||
public String getManufacturer() { | ||
return manufacturer; | ||
} | ||
|
||
@Override | ||
public void setManufacturer(String manufacturer) { | ||
this.manufacturer = manufacturer; | ||
} | ||
|
||
@Override | ||
public String getLicensePlate() { | ||
return licensePlate; | ||
} | ||
|
||
@Override | ||
public void setLicensePlate(String licensePlate) { | ||
this.licensePlate = licensePlate; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/org/apache/camel/quarkus/component/bean/validator/it/model/OptionalChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.quarkus.component.bean.validator.it.model; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public interface OptionalChecks { | ||
} |
28 changes: 28 additions & 0 deletions
28
integration-tests/bean-validator/src/main/resources/META-INF/validation.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration"> | ||
|
||
<default-provider>org.hibernate.validator.HibernateValidator</default-provider> | ||
<message-interpolator>org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator</message-interpolator> | ||
<constraint-mapping>/constraints-car.xml</constraint-mapping> | ||
|
||
</validation-config> |
Oops, something went wrong.