f1682c22db4fd51b1be185ffe35cb376197badce
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.adapter.iaas.provider.operation.impl;
25
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;
36
37 import java.util.Map;
38 import java.util.Optional;
39
40 import static java.util.Optional.of;
41 import static org.mockito.Mockito.*;
42
43 public class TestMigrateServer {
44
45     @Test
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());
51         try {
52             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
53         } catch (APPCException e) {
54             Assert.fail("Exception during MigrateServer.executeProviderOperation");
55         }
56         verify(mg.getComputeService()).migrateServer(MockGenerator.SERVER_ID);
57         verify(server, atLeastOnce()).waitForStateChange(anyInt(), anyInt(), Matchers.anyVararg());
58     }
59
60     @Test
61     public void should_returnNullAsServer(){
62
63         //  given
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();
70
71         //  when
72         when(params.get(ProviderAdapter.PROPERTY_INSTANCE_URL)).thenReturn(null);
73         try {
74             modelObject = migrateServer.executeProviderOperation(params,svcLogicContext);
75         } catch (APPCException e) {
76             Assert.fail("Exception during MigrateServer.executeProviderOperation");
77         }
78
79         //  then
80         Assert.assertNull(modelObject);
81     }
82 }