aboutsummaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/TunnelxconnTopologyOperationRPCTest.java
blob: 1c6a468fe79416dfe2a5c12c4a9b2e4874f4cbc9 (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
package org.onap.sdnc.northbound;

import static org.junit.Assert.assertEquals;
import static org.onap.sdnc.northbound.GenericResourceApiProvider.APP_NAME;
import static org.onap.sdnc.northbound.GenericResourceApiProvider.NO_SERVICE_LOGIC_ACTIVE;
import static org.onap.sdnc.northbound.GenericResourceApiProvider.NULL_OR_EMPTY_ERROR_PARAM;
import static org.onap.sdnc.northbound.util.MDSALUtil.exec;
import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation;
import static org.onap.sdnc.northbound.util.MDSALUtil.sdncRequestHeader;
import static org.onap.sdnc.northbound.util.MDSALUtil.serviceInformationBuilder;
import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation;
import static org.onap.sdnc.northbound.util.MDSALUtil.tunnelxconnResponseInformation;
import static org.onap.sdnc.northbound.util.MDSALUtil.tunnelxconnTopologyOperationInput;
import static org.onap.sdnc.northbound.util.MDSALUtil.tunnelxconnTopologyOperationOutput;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.sdnc.northbound.util.PropBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInput;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutput;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction;
import org.opendaylight.yangtools.yang.common.RpcResult;

@RunWith(MockitoJUnitRunner.class)
public class TunnelxconnTopologyOperationRPCTest extends GenericResourceApiProviderTest {


    private static final String SVC_OPERATION = "tunnelxconn-topology-operation";


    @Before
    public void setUp() throws Exception {
        super.setUp();
        svcClient.setScvOperation(SVC_OPERATION);
    }

    @Test
    public void should_fail_when_service_instance_id_not_present() throws Exception {

        TunnelxconnTopologyOperationInput input = tunnelxconnTopologyOperationInput().build();

        TunnelxconnTopologyOperationOutput output =
            exec(genericResourceApiProvider::tunnelxconnTopologyOperation, input, RpcResult::getResult);

        assertEquals("404", output.getResponseCode());
        assertEquals(NULL_OR_EMPTY_ERROR_PARAM, output.getResponseMessage());
        assertEquals("Y", output.getAckFinalIndicator());
    }

    @Test
    public void should_fail_when_client_execution_failed() throws Exception {

        svcClient.mockHasGraph(true);
        svcClient.mockExecuteWoServiceData(new RuntimeException("test exception"));

        TunnelxconnTopologyOperationInput input = tunnelxconnTopologyOperationInput()
            .setSdncRequestHeader(sdncRequestHeader()
                .setSvcRequestId("test-svc-request-id")
                .setSvcAction(SvcAction.Assign).build()
            )
            .setServiceInformation(serviceInformationBuilder()
                .setServiceInstanceId("test-service-instance-id").build()
            ).build();

        TunnelxconnTopologyOperationOutput output =
            exec(genericResourceApiProvider::tunnelxconnTopologyOperation, input, RpcResult::getResult);

        assertEquals("500", output.getResponseCode());
        assertEquals("test exception", output.getResponseMessage());
        assertEquals("Y", output.getAckFinalIndicator());
    }

    @Test
    public void should_fail_when_client_has_no_graph() throws Exception {

        svcClient.mockHasGraph(false);

        TunnelxconnTopologyOperationInput input = tunnelxconnTopologyOperationInput()
            .setSdncRequestHeader(sdncRequestHeader()
                .setSvcRequestId("test-svc-request-id")
                .setSvcAction(SvcAction.Assign).build()
            )
            .setServiceInformation(serviceInformationBuilder()
                .setServiceInstanceId("test-service-instance-id").build()
            ).build();

        TunnelxconnTopologyOperationOutput output =
            exec(genericResourceApiProvider::tunnelxconnTopologyOperation, input, RpcResult::getResult);

        assertEquals("503", output.getResponseCode());
        assertEquals(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + SVC_OPERATION + "'", output.getResponseMessage());
        assertEquals("Y", output.getAckFinalIndicator());
    }

    @Test
    public void should_success_when_no_errors_encountered() throws Exception {

        svcClient.mockHasGraph(true);
        PropBuilder svcResultProp = svcClient.createExecuteOKResult();
        svcResultProp.set("security-zone-object-path", "securityZoneObjectPath: XYZ");
        svcClient.mockExecuteWoServiceData(svcResultProp);

        TunnelxconnTopologyOperationInput input = tunnelxconnTopologyOperationInput()
            .setRequestInformation(requestInformation()
                .setRequestId("test-request-id")
                .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance).build()
            )
            .setServiceInformation(serviceInformationBuilder()
                .setServiceInstanceId("test-service-instance-id").build()
            ).build();

        TunnelxconnTopologyOperationOutput output =
            exec(genericResourceApiProvider::tunnelxconnTopologyOperation, input, RpcResult::getResult);

        assertEquals("200", output.getResponseCode());
        assertEquals("OK", output.getResponseMessage());
        assertEquals("Y", output.getAckFinalIndicator());

        TunnelxconnTopologyOperationOutput expectedOutput = createExpectedOutput(svcResultProp, input);
        assertEquals(expectedOutput, output);

    }

    private TunnelxconnTopologyOperationOutput createExpectedOutput(PropBuilder propBuilder,
        TunnelxconnTopologyOperationInput input) {

        return tunnelxconnTopologyOperationOutput()
            .setTunnelxconnResponseInformation(tunnelxconnResponseInformation()
                .setObjectPath(propBuilder.get("tunnelxconn-object-path")).build()
            )
            .setResponseCode(propBuilder.get(svcClient.errorCode))
            .setAckFinalIndicator(propBuilder.get(svcClient.ackFinal))
            .setResponseMessage(propBuilder.get(svcClient.errorMessage))
            .setServiceResponseInformation(serviceResponseInformation()
                .setInstanceId(input.getServiceInformation().getServiceInstanceId())
                .setObjectPath(propBuilder.get(svcClient.serviceObjectPath)).build()
            ).build();
    }
}