2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
25 package org.onap.appc.adapter.iaas.provider.operation.impl;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.mockito.ArgumentCaptor;
30 import org.onap.appc.exceptions.APPCException;
31 import static org.junit.Assert.assertEquals;
32 import static org.mockito.Matchers.any;
33 import static org.mockito.Mockito.doReturn;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.verify;
36 import static org.mockito.Mockito.atLeastOnce;
37 import com.att.cdp.exceptions.ZoneException;
38 import com.att.cdp.zones.model.Image;
39 import com.att.cdp.zones.model.Server;
40 import com.att.cdp.zones.model.Server.Status;
42 public class TestCreateSnapshot {
45 public void createSnapshotRunning() throws ZoneException {
46 MockGenerator mg = new MockGenerator(Status.RUNNING);
47 Server server = mg.getServer();
48 Image image = mock(Image.class);
49 doReturn("1234567").when(image).getId();
50 doReturn(mg.getContext()).when(image).getContext();
51 doReturn("wrong image name").when(image).getName();
52 doReturn(com.att.cdp.zones.model.Image.Status.ACTIVE).when(image).getStatus();
53 doReturn(image).when(mg.getImageService()).getImageByName(any());
54 CreateSnapshot rbs = new CreateSnapshot();
55 rbs.setProviderCache(mg.getProviderCacheMap());
57 rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
58 } catch (APPCException e) {
59 Assert.fail("Exception during CreateSnapshot.executeProviderOperation");
61 ArgumentCaptor<String> createSnapshotCaptor = ArgumentCaptor.forClass(String.class);
62 verify(server).createSnapshot(createSnapshotCaptor.capture());
63 ArgumentCaptor<String> getImageNameCaptor = ArgumentCaptor.forClass(String.class);
64 verify(mg.getImageService(), atLeastOnce()).getImageByName(getImageNameCaptor.capture());
65 assertEquals("in:\"" + createSnapshotCaptor.getValue() + "\"", getImageNameCaptor.getValue());