1 package org.openecomp.sdc.be.components.path;
4 import com.google.common.collect.Sets;
6 import org.junit.Before;
8 import org.mockito.InjectMocks;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.mockito.MockitoAnnotations;
12 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
13 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
14 import org.openecomp.sdc.be.model.Component;
15 import org.openecomp.sdc.be.model.ComponentParametersView;
16 import org.openecomp.sdc.be.model.Service;
17 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
18 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
19 import org.openecomp.sdc.exception.ResponseFormat;
21 import java.util.Collection;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.when;
28 public class ForwardingPathValidatorTest implements ForwardingPathTestUtils {
30 ResponseFormatManager mock;
32 private Service service = (Service) getToscaFullElement().left().value();
36 ToscaOperationFacade toscaOperationFacade;
38 ForwardingPathValidationUtilTest test = new ForwardingPathValidationUtilTest();
40 private static final String SERVICE_ID = "serviceid1";
47 MockitoAnnotations.initMocks(this);
48 mock = Mockito.mock(ResponseFormatManager.class);
49 when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(service));
50 when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
51 when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
52 when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
57 public void testValidForwardingPathName(){
59 Collection<ForwardingPathDataDefinition> paths = createData("pathName", "http", "8285", "pathName");
60 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
61 assertTrue(booleanResponseFormatEither.isLeft());
65 public void testEmptyForwardingPathName(){
66 Collection<ForwardingPathDataDefinition> paths = createData("", "protocol", "8285", "name1");
67 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test
68 .validateForwardingPaths(paths, SERVICE_ID, false);
69 assertTrue(booleanResponseFormatEither.isRight());
73 public void testLongForwardingPathName(){
74 String pathName = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
75 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
76 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
77 Collection<ForwardingPathDataDefinition> paths = createData(pathName,
78 "http", "port", "name1");
79 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test
80 .validateForwardingPaths(paths, SERVICE_ID, false);
81 assertTrue(booleanResponseFormatEither.isRight());
86 public void testUniqueForwardingPathNameUpdateName(){
88 Collection<ForwardingPathDataDefinition> paths = createData("pathName4", "httpfd", "82df85", "name1");
89 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
90 assertTrue(booleanResponseFormatEither.isLeft());
95 public void testUniqueForwardingPathNameUpdatePort(){
97 Collection<ForwardingPathDataDefinition> paths = createData("pathName3", "httpfd", "82df85", "name1");
98 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
99 assertTrue(booleanResponseFormatEither.isLeft());
104 public void testLongForwardingPathPortNumber(){
105 String port = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
106 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
107 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
108 Collection<ForwardingPathDataDefinition> paths = createData("pathName",
109 "http", port, "name1");
110 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
111 assertTrue(booleanResponseFormatEither.isRight());
116 public void testLongForwardingPathProtocol(){
117 String protocol = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
118 "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
119 "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
120 Collection<ForwardingPathDataDefinition> paths = createData("pathName",
121 protocol, "port", "name1");
122 Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
123 assertTrue(booleanResponseFormatEither.isRight());
127 private Set<ForwardingPathDataDefinition> createData(String pathName, String protocol, String ports, String uniqueId) {
129 return Sets.newHashSet(createPath(pathName, protocol, ports, uniqueId));
133 private <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
135 return Either.left((T) setUpServiceMcok());
138 private Service setUpServiceMcok(){
139 Service service = new Service();
140 service.addForwardingPath(createPath("pathName3", "http", "8285", "name1"));
144 private class ForwardingPathValidationUtilTest extends ForwardingPathValidator {
146 protected ResponseFormatManager getResponseFormatManager() {