diff options
author | 2019-02-04 10:31:04 +0000 | |
---|---|---|
committer | 2019-02-05 21:11:04 +0000 | |
commit | 8f725f853e52d00d5c40a9b78a1c2b6381d10e70 (patch) | |
tree | 3791ac4cb603d604c2077f9a2f9ed463d846c6a5 /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap | |
parent | 44a2c9c2eebf99d1118b24ab472764c2d1e31147 (diff) |
Improve test coverage of reboot
Increase line coverage from 20% to 73%
Issue-ID: APPC-1374
Change-Id: I219261a228f42df56f6988b2d5dc157e6fb10c42
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap')
-rw-r--r-- | appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java index 33ce7c2cc..876201fa6 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,23 +24,26 @@ */ package org.onap.appc.adapter.iaas.provider.operation.impl; -import static org.mockito.Mockito.inOrder; import org.onap.appc.adapter.iaas.ProviderAdapter; -import org.junit.Assert; +import org.onap.appc.adapter.iaas.impl.RequestContext; +import org.onap.appc.adapter.iaas.impl.RequestFailedException; +import org.onap.appc.configuration.ConfigurationFactory; import org.junit.Test; -import org.mockito.InOrder; +import org.mockito.Mockito; import org.onap.appc.exceptions.APPCException; import com.att.cdp.exceptions.ZoneException; +import com.att.cdp.zones.Context; import com.att.cdp.zones.model.Server; import com.att.cdp.zones.model.Server.Status; +import com.att.cdp.zones.model.Tenant; import static org.junit.Assert.assertEquals; +import java.util.Properties; public class TestRebootServer { @Test - public void should_returnNullAsServer() throws ZoneException,APPCException { + public void should_returnNullAsServer() throws ZoneException,APPCException { MockGenerator mg = new MockGenerator(Status.SUSPENDED); - Server server = mg.getServer(); RebootServer rbs = new RebootServer(); mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, "url1"); mg.getParams().put(ProviderAdapter.REBOOT_TYPE, ""); @@ -48,4 +53,39 @@ public class TestRebootServer { assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS")); } + @Test + public void rebootServerTest() throws ZoneException,APPCException, RequestFailedException { + MockGenerator mg = new MockGenerator(Status.RUNNING); + SubclassRebootServer rbs = Mockito.spy(new SubclassRebootServer()); + mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, getURL()); + mg.getParams().put(ProviderAdapter.REBOOT_TYPE, "HARD"); + mg.getParams().put("REBOOT_STATUS", "SUCCESS"); + Tenant tenant = new Tenant(); + tenant.setName("TENANT_NAME"); + mg.getContext().setTenant(tenant); + Mockito.doReturn(mg.getContext()).when(rbs).getContext(Mockito.any(RequestContext.class), Mockito.anyString(), + Mockito.anyString()); + Mockito.doReturn(mg.getServer()).when(rbs).lookupServer(Mockito.any(RequestContext.class), Mockito.any(Context.class), + Mockito.anyString()); + rbs.setProviderCache(mg.getProviderCacheMap()); + rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()); + assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS")); + } + + private String getURL() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + return String.format("http://%s:%s/v2/%s/servers/%s", props.getProperty("test.ip"), props.getProperty("test.port"), + "3b3d77e0-a79d-4c10-bfac-1b3914af1a14", "3b3d77e0-a79d-4c10-bfac-1b3914af1a14"); + } + + class SubclassRebootServer extends RebootServer { + @Override + public Context getContext(RequestContext rc, String selfLinkURL, String providerName) { + return super.getContext(rc, selfLinkURL, providerName); + } + @Override + public Server lookupServer(RequestContext rc, Context context, String id) throws ZoneException, RequestFailedException { + return super.lookupServer(rc, context, id); + } + } } |