-
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 67610a9
Showing
12 changed files
with
347 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,20 @@ | ||
=== Configuring the ValidatorFactory | ||
|
||
Implementation of this extension leverages the https://quarkus.io/guides/validation[Quarkus Hibernate Validator extension]. | ||
|
||
Therefore it is not possible to configure the `ValidatorFactory` by Camel's properties ('constraintValidatorFactory`, `messageInterpolator`, `traversableResolver`, `validationProviderResolver` and `validatorFactory`). | ||
You can configure the `ValidatorFactory` by the creation of beans which will be injected into the default `ValidatorFactory` (created by Quarkus). | ||
See the https://quarkus.io/guides/validation#hibernate-validator-extension-and-cdi[Quarkus CDI documentation] for more information. | ||
=== Custom validation groups in native mode | ||
When using custom validation groups in native mode, all the interfaces need to be registered for reflection (see the https://quarkus.io/guides/writing-native-applications-tips#register-reflection[documentation]). | ||
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
55 changes: 55 additions & 0 deletions
55
...java/org/apache/camel/quarkus/component/bean/validator/it/ValidatorFactoryCustomizer.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; | ||
|
||
import java.util.Locale; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
import javax.validation.MessageInterpolator; | ||
|
||
@ApplicationScoped | ||
public class ValidatorFactoryCustomizer { | ||
|
||
@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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...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,49 @@ | ||
/* | ||
* 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; | ||
|
||
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.