2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Copyright (C) 2019 IBM.
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.onap.appc.Constants;
30 import org.onap.appc.exceptions.APPCException;
31 import org.onap.appc.exceptions.UnknownProviderException;
33 import static org.mockito.Mockito.verify;
34 import static org.mockito.Mockito.atLeastOnce;
35 import com.att.cdp.zones.model.ModelObject;
36 import com.att.cdp.zones.model.Server;
37 import com.att.cdp.zones.model.Server.Status;
39 public class TestVmStatuschecker {
42 public void vmStatuscheckerSuspended() {
43 MockGenerator mg = new MockGenerator(Status.SUSPENDED);
44 Server server = mg.getServer();
45 VmStatuschecker rbs = new VmStatuschecker();
46 rbs.setProviderCache(mg.getProviderCacheMap());
47 ModelObject mo = null;
49 mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
50 } catch (APPCException e) {
51 Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
53 verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "suspended");
57 public void vmStatuscheckerRunning() {
58 MockGenerator mg = new MockGenerator(Status.RUNNING);
59 Server server = mg.getServer();
60 VmStatuschecker rbs = new VmStatuschecker();
61 rbs.setProviderCache(mg.getProviderCacheMap());
62 ModelObject mo = null;
64 mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
65 } catch (APPCException e) {
66 Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
68 verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "running");
72 public void vmStatuscheckerError() {
73 MockGenerator mg = new MockGenerator(Status.ERROR);
74 Server server = mg.getServer();
75 VmStatuschecker rbs = new VmStatuschecker();
76 rbs.setProviderCache(mg.getProviderCacheMap());
77 ModelObject mo = null;
79 mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
80 } catch (APPCException e) {
81 Assert.fail("Exception during VmStatuschecker.executeProviderOperation");
83 verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "error");
87 public void vmDeletedStatuscheckerError() throws APPCException {
88 MockGenerator mg = new MockGenerator(Status.DELETED);
89 Server server = mg.getServer();
90 VmStatuschecker rbs = new VmStatuschecker();
91 rbs.setProviderCache(mg.getProviderCacheMap());
92 ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
93 verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "deleted");
97 public void vmReadyStatuscheckerError() throws APPCException {
98 MockGenerator mg = new MockGenerator(Status.READY);
99 Server server = mg.getServer();
100 VmStatuschecker rbs = new VmStatuschecker();
101 rbs.setProviderCache(mg.getProviderCacheMap());
102 ModelObject mo = rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
103 verify(mg.getSvcLogicContext(), atLeastOnce()).setAttribute(Constants.STATUS_OF_VM, "ready");