aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/path/ForwardingPathValidatorTest.java
blob: fd9e25f475580f5bba358c0b7954e3fd78ab938b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package org.openecomp.sdc.be.components.path;


import com.google.common.collect.Sets;
import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;

import java.util.Collection;
import java.util.Set;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

public class ForwardingPathValidatorTest implements ForwardingPathTestUtils {

    ResponseFormatManager mock;

    private Service  service = (Service) getToscaFullElement().left().value();


    @Mock
    ToscaOperationFacade toscaOperationFacade;
    @InjectMocks
    ForwardingPathValidationUtilTest test = new ForwardingPathValidationUtilTest();

    private static final String SERVICE_ID = "serviceid1";




    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
        mock = Mockito.mock(ResponseFormatManager.class);
        when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class))).thenReturn(Either.left(service));
        when(mock.getResponseFormat(any())).thenReturn(new ResponseFormat());
        when(mock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
        when(mock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());

    }

    @Test
    public void testValidForwardingPathName(){

        Collection<ForwardingPathDataDefinition> paths = createData("pathName", "http", "8285", "pathName");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
        assertTrue(booleanResponseFormatEither.isLeft());
    }

    @Test
    public void testEmptyForwardingPathName(){
        Collection<ForwardingPathDataDefinition> paths = createData("", "protocol", "8285", "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither =   test
                .validateForwardingPaths(paths, SERVICE_ID, false);
        assertTrue(booleanResponseFormatEither.isRight());
    }

    @Test
    public void testLongForwardingPathName(){
        String pathName = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
                "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
                "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
        Collection<ForwardingPathDataDefinition> paths = createData(pathName,
                "http", "port", "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither =   test
                .validateForwardingPaths(paths, SERVICE_ID, false);
        assertTrue(booleanResponseFormatEither.isRight());

    }

    @Test
    public void testUniqueForwardingPathNameUpdateName(){

        Collection<ForwardingPathDataDefinition> paths = createData("pathName4", "httpfd", "82df85", "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
        assertTrue(booleanResponseFormatEither.isLeft());

    }

    @Test
    public void testUniqueForwardingPathNameUpdatePort(){

        Collection<ForwardingPathDataDefinition> paths = createData("pathName3", "httpfd", "82df85", "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, true);
        assertTrue(booleanResponseFormatEither.isLeft());

    }

    @Test
    public void testLongForwardingPathPortNumber(){
        String port = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
                "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
                "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
        Collection<ForwardingPathDataDefinition> paths = createData("pathName",
                "http", port, "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither = test.validateForwardingPaths(paths, SERVICE_ID, false);
        assertTrue(booleanResponseFormatEither.isRight());

    }

    @Test
    public void testLongForwardingPathProtocol(){
        String protocol = "Failed to execute goal on project catalog-be: Could not resolve dependencies for project \n" +
                "org.openecomp.sdc:catalog-be:war:1.1.0-SNAPSHOT: Failed to collect dependencies at \n" +
                "org.openecomp.sdc.common:openecomp-sdc-artifact-generator-api:jar:1802.0.1.167: ";
        Collection<ForwardingPathDataDefinition> paths = createData("pathName",
                protocol, "port", "name1");
        Either<Boolean, ResponseFormat> booleanResponseFormatEither =  test.validateForwardingPaths(paths, SERVICE_ID, false);
        assertTrue(booleanResponseFormatEither.isRight());

    }

    private Set<ForwardingPathDataDefinition> createData(String pathName, String protocol, String ports, String uniqueId) {

        return Sets.newHashSet(createPath(pathName, protocol, ports, uniqueId));
    }


    private  <T extends Component> Either<T, StorageOperationStatus> getToscaFullElement() {

        return Either.left((T) setUpServiceMcok());
    }

    private Service setUpServiceMcok(){
    Service service = new Service();
    service.addForwardingPath(createPath("pathName3", "http", "8285", "name1"));
    return  service;
    }

    private class ForwardingPathValidationUtilTest extends ForwardingPathValidator {

        protected ResponseFormatManager getResponseFormatManager() {
            return mock;
        }
    }

}