Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / ForwardingPathValidatorTest.java
1 package org.openecomp.sdc.be.components.path;
2
3
4 import com.google.common.collect.Sets;
5 import fj.data.Either;
6 import org.junit.Before;
7 import org.junit.Test;
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.jsonjanusgraph.operations.ToscaOperationFacade;
18 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
19 import org.openecomp.sdc.exception.ResponseFormat;
20
21 import java.util.Collection;
22 import java.util.Set;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.when;
27
28 public class ForwardingPathValidatorTest implements ForwardingPathTestUtils {
29
30     ResponseFormatManager mock;
31
32     private Service  service = (Service) getToscaFullElement().left().value();
33
34
35     @Mock
36     ToscaOperationFacade toscaOperationFacade;
37     @InjectMocks
38     ForwardingPathValidationUtilTest test = new ForwardingPathValidationUtilTest();
39
40     private static final String SERVICE_ID = "serviceid1";
41
42
43
44
45     @Before
46     public void init() {
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());
53
54     }
55
56     @Test
57     public void testValidForwardingPathName(){
58
59         Collection<ForwardingPathDataDefinition> paths = createData("pathName", "http", "8285", "pathName");
60         Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
61         assertTrue(booleanResponseFormatEither.isLeft());
62     }
63
64     @Test
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());
70     }
71
72     @Test
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());
82
83     }
84
85     @Test
86     public void testUniqueForwardingPathNameUpdateName(){
87
88         Collection<ForwardingPathDataDefinition> paths = createData("pathName4", "httpfd", "82df85", "name1");
89         Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
90         assertTrue(booleanResponseFormatEither.isLeft());
91
92     }
93
94     @Test
95     public void testUniqueForwardingPathNameUpdatePort(){
96
97         Collection<ForwardingPathDataDefinition> paths = createData("pathName3", "httpfd", "82df85", "name1");
98         Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
99         assertTrue(booleanResponseFormatEither.isLeft());
100
101     }
102
103     @Test
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());
112
113     }
114
115     @Test
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());
124
125     }
126
127     private Set<ForwardingPathDataDefinition> createData(String pathName, String protocol, String ports, String uniqueId) {
128
129         return Sets.newHashSet(createPath(pathName, protocol, ports, uniqueId));
130     }
131
132
133     private  <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {
134
135         return Either.left((T) setUpServiceMcok());
136     }
137
138     private Service setUpServiceMcok(){
139     Service service = new Service();
140     service.addForwardingPath(createPath("pathName3", "http", "8285", "name1"));
141     return  service;
142     }
143
144     private class ForwardingPathValidationUtilTest extends ForwardingPathValidator {
145
146         protected ResponseFormatManager getResponseFormatManager() {
147             return mock;
148         }
149     }
150
151 }