Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7.x] JBPM-6913 (RHPAM-462): New Instances in RadioGroups, ListBoxes and Multiple Subforms are missing the required annotation. #1880

Merged
merged 1 commit into from Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,6 +16,9 @@

package org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
Expand All @@ -34,13 +37,20 @@
)
public class CharacterSelectorOption implements SelectorOption<Character> {

@FormField(labelKey = "value")
@FormField(
labelKey = "value",
required = true
)
@NotNull
private Character value;

@FormField(
labelKey = "text",
afterElement = "value"
afterElement = "value",
required = true
)
@NotEmpty
@NotNull
private String text;

public CharacterSelectorOption() {
Expand Down
Expand Up @@ -16,6 +16,9 @@

package org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
Expand All @@ -34,13 +37,20 @@
)
public class DecimalSelectorOption implements SelectorOption<Double> {

@FormField(labelKey = "value")
@FormField(
labelKey = "value",
required = true
)
@NotNull
private Double value;

@FormField(
labelKey = "text",
afterElement = "value"
afterElement = "value",
required = true
)
@NotEmpty
@NotNull
private String text;

public DecimalSelectorOption() {
Expand Down
Expand Up @@ -16,6 +16,9 @@

package org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
Expand All @@ -34,13 +37,20 @@
)
public class IntegerSelectorOption implements SelectorOption<Long> {

@FormField(labelKey = "value")
@FormField(
labelKey = "value",
required = true
)
@NotNull
private Long value;

@FormField(
labelKey = "text",
afterElement = "value"
afterElement = "value",
required = true
)
@NotEmpty
@NotNull
private String text;

public IntegerSelectorOption() {
Expand Down
Expand Up @@ -40,8 +40,11 @@
public class TableColumnMeta {

@FormField(
labelKey = "label"
labelKey = "label",
required = true
)
@NotEmpty
@NotNull
private String label;

@FormField(
Expand Down
Expand Up @@ -16,12 +16,18 @@

package org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

Expand All @@ -47,13 +53,6 @@ public void init() {
option = newSelectorOption(valueA, LABEL_A);
}

@Test
public void testDefaultConstructor() {
option = new IntegerSelectorOption();
assertNull(option.getText());
assertNull(option.getValue());
}

@Test
public void testGetValue() {
assertSame(valueA, option.getValue());
Expand Down Expand Up @@ -91,4 +90,24 @@ private void testEquals(TYPE valueA, String textA, TYPE valueB, String textB, bo
assertTrue(anOption.equals(other) == shouldBeEqual);
assertEquals(anOption.hashCode() == other.hashCode(), shouldBeEqual);
}

@Test
public void testValidateOption() {

final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

SelectorOption emptyOption = newSelectorOption(null, null);

Set<ConstraintViolation<SelectorOption>> violations = validator.validate(emptyOption);

Assertions.assertThat(violations)
.isNotNull()
.isNotEmpty();

violations = validator.validate(option);

Assertions.assertThat(violations)
.isNotNull()
.isEmpty();
}
}
@@ -0,0 +1,53 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* 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.
*/

package org.kie.workbench.common.forms.fields.shared.fieldTypes.relations;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;

import org.assertj.core.api.Assertions;
import org.junit.Test;

public class TableColumnMetaTest {

private static final String COLUMN = "column";

@Test
public void testValidate() {
final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

TableColumnMeta emptyColumnMeta = new TableColumnMeta();

Set<ConstraintViolation<TableColumnMeta>> violations = validator.validate(emptyColumnMeta);

Assertions.assertThat(violations)
.isNotNull()
.isNotEmpty();


TableColumnMeta columnMeta = new TableColumnMeta(COLUMN, COLUMN);

violations = validator.validate(columnMeta);

Assertions.assertThat(violations)
.isNotNull()
.isEmpty();
}
}