2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.services;
23 public class QuestionnaireValidatorTest {
25 public static QuestionnaireValidator validator = new QuestionnaireValidator();
27 @Test(expectedExceptions = CoreException.class)
28 public void testAddSubEntityBeforeRoot_negative() {
29 validator.addSubEntity(createComponent("componentId2"), CompositionEntityType.vsp);
32 @Test(dependsOnMethods = "testAddSubEntityBeforeRoot_negative")
33 public void testAddRootEntity() {
34 validator.addRootEntity(createVspQuestionnaireEntity());
37 @Test(dependsOnMethods = "testAddRootEntity", expectedExceptions = CoreException.class)
38 public void testAddRootEntityWhenAlreadyExist_negative() {
39 validator.addRootEntity(createVspQuestionnaireEntity());
42 @Test(dependsOnMethods = "testAddRootEntity")
43 public void testAddSubEntity() {
44 validator.addSubEntity(createComponent("componentId1"), CompositionEntityType.vsp);
47 @Test(dependsOnMethods = "testAddRootEntity", expectedExceptions = CoreException.class)
48 public void testAddSubEntityWithNonExistingParentType() {
49 validator.addSubEntity(new ComponentEntity("vspId1", new Version(0, 1), "componentId2"), CompositionEntityType.nic);
52 @Test(dependsOnMethods = "testAddSubEntity")
53 public void testAddSubEntities() throws Exception {
54 Collection<UnifiedCompositionEntity> nics = new ArrayList<>();
55 nics.add(createNic("nicId1", "componentId1"));
56 nics.add(createNic("nicId2", "componentId1"));
57 nics.add(createNic("nicId3", "componentId1"));
59 validator.addSubEntities(nics, CompositionEntityType.component);
63 @Test(dependsOnMethods = "testAddSubEntities")
64 public void testValidate() throws Exception {
65 QuestionnaireValidationResult validationResult = validator.validate();
66 Assert.assertTrue(validationResult.isValid());
69 private static VspQuestionnaireEntity createVspQuestionnaireEntity() {
70 VspQuestionnaireEntity vspQuestionnaireEntity = new VspQuestionnaireEntity();
71 vspQuestionnaireEntity.setId("vspId1");
72 vspQuestionnaireEntity.setVersion(new Version(0, 1));
73 vspQuestionnaireEntity.setQuestionnaireData("{\n" +
74 " \"name\": \"bla bla\"\n" +
76 return vspQuestionnaireEntity;
79 private static ComponentEntity createComponent(String componentId) {
80 ComponentEntity component = new ComponentEntity("vspId1", new Version(0, 1), componentId);
81 component.setQuestionnaireData("{\n" +
82 " \"name\": \"bla bla\"\n" +
87 private static UnifiedCompositionEntity createNic(String nicId, String componentId) {
88 NicEntity nic = new NicEntity("vspId1", new Version(0, 1), componentId, nicId);
89 nic.setQuestionnaireData("{\n" +
90 " \"name\": \"bla bla\"\n" +