/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.List;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
/**
* DAO test for ToscaEntrySchema.
private static final String A_DESCRIPTION = "A Description";
@Test
- public void testEntrySchemaPojo() {
+ public void testEntrySchemaNull() {
assertNotNull(new JpaToscaSchemaDefinition(new PfConceptKey()));
assertNotNull(new JpaToscaSchemaDefinition(new JpaToscaSchemaDefinition(new PfConceptKey())));
assertThatThrownBy(() -> new JpaToscaSchemaDefinition((JpaToscaSchemaDefinition) null))
.hasMessageMatching("copyConcept is marked .*on.*ull but is null");
+ }
+ @Test
+ public void testEntrySchema() {
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey);
new JpaToscaSchemaDefinition(typeKey).clean();
tes.clean();
assertEquals(tdtClone0, tes);
+ }
+
+ @Test
+ public void testEntrySchemaValidation() {
+ PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
+ JpaToscaSchemaDefinition tes = setUpJpaToscaSchemaDefinition(typeKey);
- assertTrue(new JpaToscaSchemaDefinition(typeKey).validate(new PfValidationResult()).isValid());
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaSchemaDefinition(typeKey).validate("").isValid());
+ assertTrue(tes.validate("").isValid());
tes.setType(PfConceptKey.getNullKey());
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setType(null);
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setType(typeKey);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
tes.setDescription("");
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.setDescription(A_DESCRIPTION);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
tes.getConstraints().add(null);
- assertFalse(tes.validate(new PfValidationResult()).isValid());
+ assertFalse(tes.validate("").isValid());
tes.getConstraints().remove(null);
- assertTrue(tes.validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate("").isValid());
+
+ assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
+ }
+
+ private JpaToscaSchemaDefinition setUpJpaToscaSchemaDefinition(PfConceptKey typeKey) {
+ JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey);
+ tes.setDescription(A_DESCRIPTION);
+
+ List<JpaToscaConstraint> constraints = new ArrayList<>();
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
+ constraints.add(lsc);
+ tes.setConstraints(constraints);
- assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ return tes;
}
}