2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.be.components.path;
24 import com.google.common.collect.Sets;
25 import fj.data.Either;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
33 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
34 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
35 import org.openecomp.sdc.be.model.Component;
36 import org.openecomp.sdc.be.model.ComponentParametersView;
37 import org.openecomp.sdc.be.model.Service;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
39 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
40 import org.openecomp.sdc.exception.ResponseFormat;
42 import java.util.Collection;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.Mockito.when;
48 public class ForwardingPathValidatorTest implements ForwardingPathTestUtils {
50 ResponseFormatManager mock;
52 private Service service = (Service) getToscaFullElement().left().value();
56 ToscaOperationFacade toscaOperationFacade;
58 ForwardingPathValidationUtilTest test = new ForwardingPathValidationUtilTest();
60 private static final String SERVICE_ID = "serviceid1";
67 MockitoAnnotations.initMocks(this);
68 mock = Mockito.mock(ResponseFormatManager.class);
69 when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(service));
70 when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
71 when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
72 when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
77 public void testValidForwardingPathName(){
78 Collection<ForwardingPathDataDefinition> paths = createData("pathName", "http", "8285", "pathName");
79 test.validateForwardingPaths(paths, SERVICE_ID, false);
82 @Test(expected = ComponentException.class)
83 public void testEmptyForwardingPathName(){
84 Collection<ForwardingPathDataDefinition> paths = createData("", "protocol", "8285", "name1");
85 test.validateForwardingPaths(paths, SERVICE_ID, false);
88 @Test(expected = ComponentException.class)
89 public void testLongForwardingPathName(){
90 String pathName = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
91 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
92 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
93 Collection<ForwardingPathDataDefinition> paths = createData(pathName,
94 "http", "port", "name1");
95 test.validateForwardingPaths(paths, SERVICE_ID, false);
100 public void testUniqueForwardingPathNameUpdateName(){
101 Collection<ForwardingPathDataDefinition> paths = createData("pathName4", "httpfd", "82df85", "name1");
102 test.validateForwardingPaths(paths, SERVICE_ID, true);
106 public void testUniqueForwardingPathNameUpdatePort(){
107 Collection<ForwardingPathDataDefinition> paths = createData("pathName3", "httpfd", "82df85", "name1");
108 test.validateForwardingPaths(paths, SERVICE_ID, true);
111 @Test(expected = ComponentException.class)
112 public void testLongForwardingPathPortNumber(){
113 String port = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
114 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
115 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
116 Collection<ForwardingPathDataDefinition> paths = createData("pathName",
117 "http", port, "name1");
118 test.validateForwardingPaths(paths, SERVICE_ID, false);
122 @Test(expected = ComponentException.class)
123 public void testLongForwardingPathProtocol(){
124 String protocol = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
125 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
126 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
127 Collection<ForwardingPathDataDefinition> paths = createData("pathName",
128 protocol, "port", "name1");
129 test.validateForwardingPaths(paths, SERVICE_ID, false);
133 private Set<ForwardingPathDataDefinition> createData(String pathName, String protocol, String ports, String uniqueId) {
135 return Sets.newHashSet(createPath(pathName, protocol, ports, uniqueId));
139 private <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
141 return Either.left((T) setUpServiceMcok());
144 private Service setUpServiceMcok(){
145 Service service = new Service();
146 service.addForwardingPath(createPath("pathName3", "http", "8285", "name1"));
150 private class ForwardingPathValidationUtilTest extends ForwardingPathValidator {
152 protected ResponseFormatManager getResponseFormatManager() {