2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.iaas.provider.operation.impl;
26 import com.att.cdp.zones.model.ModelObject;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.mockito.Matchers;
30 import org.onap.appc.adapter.iaas.ProviderAdapter;
31 import org.onap.appc.exceptions.APPCException;
32 import com.att.cdp.exceptions.ZoneException;
33 import com.att.cdp.zones.model.Server;
34 import com.att.cdp.zones.model.Server.Status;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import java.util.Optional;
40 import static java.util.Optional.of;
41 import static org.mockito.Mockito.*;
43 public class TestMigrateServer {
46 public void should_migrateSuspendedServer() throws ZoneException {
47 MockGenerator mg = new MockGenerator(Status.SUSPENDED);
48 Server server = mg.getServer();
49 MigrateServer rbs = new MigrateServer();
50 rbs.setProviderCache(mg.getProviderCacheMap());
52 rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
53 } catch (APPCException e) {
54 Assert.fail("Exception during MigrateServer.executeProviderOperation");
56 verify(mg.getComputeService()).migrateServer(MockGenerator.SERVER_ID);
57 verify(server, atLeastOnce()).waitForStateChange(anyInt(), anyInt(), Matchers.anyVararg());
61 public void should_returnNullAsServer(){
64 Map<String, String> params = mock(Map.class);
65 SvcLogicContext svcLogicContext = mock(SvcLogicContext.class);
66 MockGenerator mockGenerator = new MockGenerator(Status.READY);
67 MigrateServer migrateServer = new MigrateServer();
68 migrateServer.setProviderCache(mockGenerator.getProviderCacheMap());
69 ModelObject modelObject = new Server();
72 when(params.get(ProviderAdapter.PROPERTY_INSTANCE_URL)).thenReturn(null);
74 modelObject = migrateServer.executeProviderOperation(params,svcLogicContext);
75 } catch (APPCException e) {
76 Assert.fail("Exception during MigrateServer.executeProviderOperation");
80 Assert.assertNull(modelObject);