import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
-import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.NicManager;
-import org.openecomp.sdc.vendorsoftwareproduct.NicManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicRequestDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import javax.ws.rs.core.Response;
import java.util.Collection;
import java.util.UUID;
import static org.mockito.MockitoAnnotations.initMocks;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.mockito.Mockito.when;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({NicsImpl.class, ComponentManagerFactory.class, NicManagerFactory.class})
public class NicsImplTest {
private Logger logger = LoggerFactory.getLogger(NicsImplTest.class);
- @Mock
- private NicManagerFactory nicManagerFactory;
-
@Mock
private NicManager nicManager;
- @Mock
- private ComponentManagerFactory componentManagerFactory;
-
@Mock
private ComponentManager componentManager;
private final String nicId = "" + System.currentTimeMillis();
private final String user = "cs0008";
+ private NicsImpl bean;
+
@Before
public void setUp() {
try {
initMocks(this);
- mockStatic(ComponentManagerFactory.class);
- when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
- when(componentManagerFactory.createInterface()).thenReturn(componentManager);
-
- mockStatic(NicManagerFactory.class);
- when(NicManagerFactory.getInstance()).thenReturn(nicManagerFactory);
- when(nicManagerFactory.createInterface()).thenReturn(nicManager);
-
-
-
NicEntity e = new NicEntity();
e.setComponentId(componentId);
e.setId(nicId);
ArgumentMatchers.eq(componentId),
ArgumentMatchers.eq(nicId))).thenReturn(qr);
+ bean = new NicsImpl(nicManager, componentManager);
} catch (Exception e) {
logger.error(e.getMessage(), e);
@Test
public void testList() {
- NicsImpl bean = new NicsImpl();
Response rsp = bean.list(vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
dto.setNetworkId(nicId);
dto.setNetworkType("External");
- NicsImpl bean = new NicsImpl();
Response rsp = bean.create(dto, vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Object e = rsp.getEntity();
@Test
public void testDelete() {
- NicsImpl bean = new NicsImpl();
Response rsp = bean.delete(vspId, versionId, componentId, nicId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNull(rsp.getEntity());
@Test
public void testGet() {
- NicsImpl bean = new NicsImpl();
Response rsp = bean.get(vspId, versionId, componentId, nicId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNotNull(rsp.getEntity());
@Test
public void testUpdate() {
- NicsImpl bean = new NicsImpl();
NicRequestDto dto = new NicRequestDto();
dto.setDescription("hello");
dto.setName("name");
@Test
public void testGetQuestionaire() {
- NicsImpl bean = new NicsImpl();
Response rsp = bean.getQuestionnaire(vspId, versionId, componentId, nicId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
try {
@Test
public void testUpdateQuestionaire() {
- NicsImpl bean = new NicsImpl();
Response rsp = bean.updateQuestionnaire("helloworld", vspId, versionId, componentId, nicId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNull(rsp.getEntity());