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.dao.type.ComponentEntity;
import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRequestDto;
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({ComponentsImpl.class, ComponentManagerFactory.class})
public class ComponentImplTest {
private Logger logger = LoggerFactory.getLogger(ComponentImplTest.class);
-
- @Mock
- private ComponentManagerFactory componentManagerFactory;
-
@Mock
private ComponentManager componentManager;
private final String componentId = "" + System.currentTimeMillis();
private final String user = "cs0008";
+ private ComponentsImpl ci;
+
@Before
public void setUp() {
try {
initMocks(this);
- mockStatic(ComponentManagerFactory.class);
- when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory);
- when(componentManagerFactory.createInterface()).thenReturn(componentManager);
-
ComponentEntity ce = new ComponentEntity();
ce.setId(vspId);
ce.setVspId(vspId);
ArgumentMatchers.any(),
ArgumentMatchers.eq(componentId))).thenReturn(qr);
+ ci = new ComponentsImpl(componentManager);
+
} catch (Exception e) {
logger.error(e.getMessage(), e);
@Test
public void testList() {
- ComponentsImpl ci = new ComponentsImpl();
-
Response rsp = ci.list(vspId, versionId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Object e = rsp.getEntity();
@Test
public void testDeleteList() {
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.deleteList(vspId, versionId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNull(rsp.getEntity());
dto.setName("name");
dto.setDisplayName("world");
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.create(dto, vspId, versionId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Object e = rsp.getEntity();
@Test
public void testDelete() {
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.delete(vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNull(rsp.getEntity());
@Test
public void testGet() {
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.get(vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNotNull(rsp.getEntity());
@Test
public void testUpdate() {
- ComponentsImpl ci = new ComponentsImpl();
ComponentRequestDto dto = new ComponentRequestDto();
Response rsp = ci.update(dto, vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
@Test
public void testGetQuestionaire() {
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.getQuestionnaire(vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
try {
@Test
public void testUpdateQuestionaire() {
- ComponentsImpl ci = new ComponentsImpl();
Response rsp = ci.updateQuestionnaire("helloworld", vspId, versionId, componentId, user);
Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
Assert.assertNull(rsp.getEntity());