summaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/topology/TopologyServiceTest.java
blob: 96703efa871fe476306c2042eec2cffebfbf9fde (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
152
153
154
155
156
/*-
 * ============LICENSE_START=======================================================
 * ONAP : APPC
 * ================================================================================
 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Copyright (C) 2017 Amdocs
 * =============================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ============LICENSE_END=========================================================
 */

package org.onap.appc.provider.topology;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.UUID;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
import org.onap.appc.provider.AppcProvider;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.internal.verification.VerificationModeFactory.times;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({TopologyService.class, ConfigurationFactory.class})
public class TopologyServiceTest {
    @Mock
    private AppcProvider appcProvider;
    private TopologyService topologyService;

    @Before
    public void setUp() throws Exception {
        mockStatic(ConfigurationFactory.class);
        Configuration configuration = mock(Configuration.class);
        when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
        doReturn("NODE_NAME").when(configuration).getProperty("appc.provider.vfodl.url");

        topologyService = spy(new TopologyService(appcProvider));
    }

    @Test
    public void modifyConfig() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        ConfigPayload configPayload = mock(ConfigPayload.class);
        doReturn("url").when(configPayload).getConfigUrl();
        doReturn("configJson").when(configPayload).getConfigJson();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.modifyConfig(commonRequestHeader, configPayload);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

    @Test
    public void migrate() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        VnfResource vnfResource = mock(VnfResource.class);
        UUID uuid = mock(UUID.class);
        doReturn("uuid-value").when(uuid).getValue();
        doReturn(uuid).when(vnfResource).getVmId();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.migrate(commonRequestHeader, vnfResource);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

    @Test
    public void restart() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        VnfResource vnfResource = mock(VnfResource.class);
        UUID uuid = mock(UUID.class);
        doReturn("uuid-value").when(uuid).getValue();
        doReturn(uuid).when(vnfResource).getVmId();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.restart(commonRequestHeader, vnfResource);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

    @Test
    public void rebuild() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        VnfResource vnfResource = mock(VnfResource.class);
        UUID uuid = mock(UUID.class);
        doReturn("uuid-value").when(uuid).getValue();
        doReturn(uuid).when(vnfResource).getVmId();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.rebuild(commonRequestHeader, vnfResource);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

    @Test
    public void snapshot() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        VnfResource vnfResource = mock(VnfResource.class);
        UUID uuid = mock(UUID.class);
        doReturn("uuid-value").when(uuid).getValue();
        doReturn(uuid).when(vnfResource).getVmId();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.snapshot(commonRequestHeader, vnfResource);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

    @Test
    public void vmstatuscheck() throws Exception {
        CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
        doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
        VnfResource vnfResource = mock(VnfResource.class);
        UUID uuid = mock(UUID.class);
        doReturn("uuid-value").when(uuid).getValue();
        doReturn(uuid).when(vnfResource).getVmId();
        PowerMockito.doReturn(true).when(topologyService, "callGraph", any());

        topologyService.vmstatuscheck(commonRequestHeader, vnfResource);

        verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
    }

}