Created new test classes for SDC-Listener.
Contains changes reverted by Patrick.
Issue-Id :APPC-246
Change-Id: I593b23bae44db0046f513f4b6a159a86bf8cc885
Signed-off-by: Abhai Singh <Abhai.Singh@amdocs.com>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <inherited>true</inherited> -->
<configuration>
- <source>1.7</source>
- <target>1.7</target>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
private static final EELFLogger logger = EELFManager.getInstance().getLogger(ArtifactProcessorFactory.class);
- private ArtifactProcessorFactory (){
+ public ArtifactProcessorFactory (){
}
* @param storeUri
* @return
*/
- public static ArtifactProcessor getArtifactProcessor(IDistributionClient client, EventSender eventSender,
+ public ArtifactProcessor getArtifactProcessor(IDistributionClient client, EventSender eventSender,
INotificationData notification, IResourceInstance resource,
IArtifactInfo artifact, URI storeUri) {
public class SdcCallback implements INotificationCallback {
private final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCallback.class);
+ private ArtifactProcessorFactory artifactProcessorFactory=new ArtifactProcessorFactory();
private URI storeUri;
private IDistributionClient client;
if (isRunning.get()) {
for(IArtifactInfo artifact:data.getServiceArtifacts()){
- ArtifactProcessor artifactProcessor = ArtifactProcessorFactory.getArtifactProcessor(client, eventSender, data, null, artifact, storeUri);
+ ArtifactProcessor artifactProcessor = artifactProcessorFactory.getArtifactProcessor(client, eventSender, data, null, artifact, storeUri);
if(artifactProcessor!=null){
executor.submit(artifactProcessor);
}
if (executor.getQueue().size() >= threadCount) {
// log warning about job backlog
}
- ArtifactProcessor artifactProcessor = ArtifactProcessorFactory.getArtifactProcessor(client, eventSender, data, resource, artifact, storeUri);
+ ArtifactProcessor artifactProcessor = artifactProcessorFactory.getArtifactProcessor(client, eventSender, data, resource, artifact, storeUri);
if(artifactProcessor != null){
executor.submit(artifactProcessor);
}
--- /dev/null
+package org.openecomp.appc.sdc.artifacts.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.appc.adapter.message.EventSender;
+import org.openecomp.appc.sdc.artifacts.object.SDCArtifact;
+import org.openecomp.sdc.api.IDistributionClient;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
+import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
+import org.powermock.api.mockito.PowerMockito;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TestArtifactProcessor {
+
+ AbstractArtifactProcessor abstractArtifactProcessor;
+
+ @Before
+ public void setup() throws Exception{
+ IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
+ EventSender eventSender = PowerMockito.mock(EventSender.class);
+ abstractArtifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
+ ,getServiceArtifacts().get(0),null));
+ }
+
+ @Test
+ public void testGetArtifactObject(){
+ SDCArtifact artifact=abstractArtifactProcessor.getArtifactObject("test");
+ Assert.assertEquals("abcd-efgh-ijkl",artifact.getArtifactUUID());
+ Assert.assertEquals("VF_LICENSE",artifact.getArtifactType());
+ Assert.assertEquals("Vnf",artifact.getResourceName());
+ Assert.assertEquals("1.0",artifact.getResourceVersion());
+ Assert.assertEquals("test",artifact.getArtifactContent());
+ }
+
+ @Test
+ public void testFactoryForLicense() throws Exception{
+ IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
+ EventSender eventSender = PowerMockito.mock(EventSender.class);
+ ArtifactProcessorFactory factory=new ArtifactProcessorFactory();
+ Assert.assertTrue(factory.getArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
+ ,getServiceArtifacts().get(0),null) instanceof LicenseArtifactProcessor);
+ }
+
+ @Test
+ public void testFactoryForConfig() throws Exception{
+ IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
+ EventSender eventSender = PowerMockito.mock(EventSender.class);
+ ArtifactProcessorFactory factory=new ArtifactProcessorFactory();
+ Assert.assertTrue(factory.getArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
+ ,getServiceArtifactsForConfig().get(0),null) instanceof ConfigArtifactProcessor);
+ }
+
+ private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
+
+ INotificationData notificationData = (INotificationData)getObject("org.openecomp.sdc.impl.NotificationDataImpl");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+
+ invokeMethod(notificationData, "setServiceArtifacts", serviceArtifacts);
+ return notificationData;
+ }
+
+ private List<IResourceInstance> getResources() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IResourceInstance> resources = new ArrayList<>();
+ IResourceInstance resource = (IResourceInstance)getObject("org.openecomp.sdc.impl.JsonContainerResourceInstance");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+ invokeMethod(resource,"setArtifacts",serviceArtifacts);
+ invokeMethod(resource,"setResourceName","Vnf");
+ invokeMethod(resource,"setResourceVersion","1.0");
+
+ resources.add(resource);
+ return resources;
+ }
+
+ private void invokeMethod(Object object, String methodName,Object... arguments) throws IllegalAccessException, InvocationTargetException {
+ Method[] methods = object.getClass().getDeclaredMethods();
+ for(Method method:methods){
+ if(methodName.equalsIgnoreCase(method.getName())){
+ method.setAccessible(true);
+ method.invoke(object,arguments);
+ }
+ }
+ }
+
+ private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ Constructor constructor = Arrays.asList(Class.forName(fqcn).getDeclaredConstructors())
+ .stream()
+ .filter(constructor1 -> constructor1.getParameterCount()==0)
+ .collect(Collectors.toList())
+ .get(0);
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+
+ private List<IArtifactInfo> getServiceArtifacts() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IArtifactInfo> serviceArtifacts = new ArrayList<>();
+ IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo,"setArtifactType","VF_LICENSE");
+ invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ serviceArtifacts.add(artifactInfo);
+ return serviceArtifacts;
+ }
+
+ private List<IArtifactInfo> getServiceArtifactsForConfig() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IArtifactInfo> serviceArtifacts = new ArrayList<>();
+ IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo,"setArtifactType","APPC_CONFIG");
+ invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ serviceArtifacts.add(artifactInfo);
+ return serviceArtifacts;
+ }
+
+}
--- /dev/null
+package org.openecomp.appc.sdc.artifacts.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.openecomp.appc.adapter.message.EventSender;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.sdc.artifacts.helper.ArtifactStorageService;
+import org.openecomp.appc.sdc.artifacts.object.SDCArtifact;
+import org.openecomp.sdc.api.IDistributionClient;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
+import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.verify;
+
+@RunWith(PowerMockRunner.class)
+public class TestLicenseArtifactProcessor {
+
+ private LicenseArtifactProcessor artifactProcessor;
+ private ArtifactStorageService storageService;
+
+ @Before
+ public void setup() throws Exception{
+ IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
+ EventSender eventSender = PowerMockito.mock(EventSender.class);
+ storageService = PowerMockito.mock(ArtifactStorageService.class);
+ artifactProcessor = Mockito.spy(new LicenseArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
+ ,getServiceArtifacts().get(0),null));
+ Whitebox.setInternalState(artifactProcessor,"artifactStorageService", storageService);
+ PowerMockito.doCallRealMethod().when(artifactProcessor).processArtifact((SDCArtifact)Matchers.anyObject());
+ PowerMockito.doNothing().when(storageService).storeSDCArtifact(Matchers.anyObject());
+ }
+
+ @Test(expected = org.openecomp.appc.exceptions.APPCException.class)
+ public void testProcessArtifactWithMissingData() throws APPCException {
+ SDCArtifact artifact=new SDCArtifact();
+ artifact.setResourceVersion("RESOURCE VERSION");
+ artifact.setArtifactUUID("123-456-789");
+ artifactProcessor.processArtifact(artifact);
+ }
+ @Test
+ public void testProcessArtifact() throws APPCException {
+ PowerMockito.when(storageService.retrieveSDCArtifact(anyString(),anyString(),anyString())).thenReturn(null);
+ SDCArtifact artifact=new SDCArtifact();
+ artifact.setResourceVersion("RESOURCE VERSION");
+ artifact.setArtifactUUID("123-456-789");
+ artifact.setResourceName("Resource Name");
+ artifactProcessor.processArtifact(artifact);
+ verify(storageService,Mockito.times(1)).storeSDCArtifact(anyObject());
+ }
+ @Test
+ public void testProcessArtifactWithDuplicateArtifact() throws APPCException {
+ SDCArtifact artifact=new SDCArtifact();
+ artifact.setResourceVersion("RESOURCE VERSION");
+ artifact.setArtifactUUID("123-456-789");
+ artifact.setResourceName("Resource Name");
+ PowerMockito.when(storageService.retrieveSDCArtifact(anyString(),anyString(),anyString())).thenReturn(artifact);
+ artifactProcessor.processArtifact(artifact);
+ verify(storageService,Mockito.times(0)).storeSDCArtifact(anyObject());
+ }
+
+ private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
+
+ org.openecomp.sdc.api.notification.INotificationData notificationData = (INotificationData)getObject("org.openecomp.sdc.impl.NotificationDataImpl");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+
+ invokeMethod(notificationData, "setServiceArtifacts", serviceArtifacts);
+ return notificationData;
+ }
+
+ private List<IResourceInstance> getResources() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IResourceInstance> resources = new ArrayList<>();
+ IResourceInstance resource = (IResourceInstance)getObject("org.openecomp.sdc.impl.JsonContainerResourceInstance");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+ invokeMethod(resource,"setArtifacts",serviceArtifacts);
+ invokeMethod(resource,"setResourceName","Vnf");
+ invokeMethod(resource,"setResourceVersion","1.0");
+
+ resources.add(resource);
+ return resources;
+ }
+
+ private void invokeMethod(Object object, String methodName,Object... arguments) throws IllegalAccessException, InvocationTargetException {
+ Method[] methods = object.getClass().getDeclaredMethods();
+ for(Method method:methods){
+ if(methodName.equalsIgnoreCase(method.getName())){
+ method.setAccessible(true);
+ method.invoke(object,arguments);
+ }
+ }
+ }
+
+ private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ Constructor constructor = Arrays.asList(Class.forName(fqcn).getDeclaredConstructors())
+ .stream()
+ .filter(constructor1 -> constructor1.getParameterCount()==0)
+ .collect(Collectors.toList())
+ .get(0);
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+
+ private List<IArtifactInfo> getServiceArtifacts() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IArtifactInfo> serviceArtifacts = new ArrayList<>();
+ IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo,"setArtifactType","TOSCA_CSAR");
+ invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ serviceArtifacts.add(artifactInfo);
+ return serviceArtifacts;
+ }
+}
package org.openecomp.appc.sdc.listener;
+
+import org.junit.Assert;
import org.junit.Before;
+import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.openecomp.appc.adapter.message.EventSender;
import org.openecomp.appc.sdc.artifacts.helper.ArtifactStorageService;
+import org.openecomp.appc.sdc.artifacts.helper.DependencyModelGenerator;
import org.openecomp.appc.sdc.artifacts.impl.ArtifactProcessorFactory;
import org.openecomp.appc.sdc.artifacts.impl.ToscaCsarArtifactProcessor;
import org.openecomp.appc.sdc.artifacts.object.SDCArtifact;
+import org.openecomp.appc.sdc.artifacts.object.SDCReference;
import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.consumer.IDistributionStatusMessage;
import org.openecomp.sdc.api.consumer.INotificationCallback;
import org.openecomp.sdc.api.notification.IArtifactInfo;
import org.openecomp.sdc.api.notification.INotificationData;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.mockito.Matchers.anyObject;
@RunWith(PowerMockRunner.class)
@PrepareForTest({IDistributionClient.class,
- EventSender.class,
- ArtifactStorageService.class,
- ToscaCsarArtifactProcessor.class,
- ArtifactProcessorFactory.class})
+ EventSender.class,
+ ArtifactStorageService.class,
+ ToscaCsarArtifactProcessor.class,
+ ArtifactProcessorFactory.class,
+ DependencyModelGenerator.class})
public class SdcCallbackTest {
- IDistributionClient client;
- private EventSender eventSender;
private INotificationCallback sdcCallback;
private ArtifactStorageService storageService;
private ToscaCsarArtifactProcessor artifactProcessor;
+ private String resourceContent;
@Before
public void setup() throws Exception {
- client = PowerMockito.mock(IDistributionClient.class);
- eventSender = PowerMockito.mock(EventSender.class);
- sdcCallback = new SdcCallback(null,client);
-
- artifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(client,eventSender,getNotificationData(),getResources().get(0)
- ,getServiceArtifacts().get(0),null));
+ IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
+ EventSender eventSender = PowerMockito.mock(EventSender.class);
+ sdcCallback = new SdcCallback(null, client);
+ resourceContent=readInput("/output/resource-ResourceAppc-template.yml").replaceAll(System.lineSeparator(),"");
+ artifactProcessor = Mockito.spy(new ToscaCsarArtifactProcessor(client, eventSender, getNotificationData(), getResources().get(0)
+ , getServiceArtifacts().get(0), null));
storageService = PowerMockito.mock(ArtifactStorageService.class);
Whitebox.setInternalState(artifactProcessor,"artifactStorageService", storageService);
+ DependencyModelGenerator dependencyModelGeneratorMock=PowerMockito.mock(DependencyModelGenerator.class);
+ PowerMockito.when(dependencyModelGeneratorMock.getDependencyModel(Matchers.anyString(),Matchers.anyString()))
+ .thenReturn("Dependency_model");
+ Whitebox.setInternalState(artifactProcessor,"dependencyModelGenerator",dependencyModelGeneratorMock);
- PowerMockito.doCallRealMethod().when(artifactProcessor).processArtifact((IDistributionClientDownloadResult) Matchers.anyObject());
+ PowerMockito.doCallRealMethod().when(artifactProcessor).processArtifact(anyObject());
PowerMockito.doCallRealMethod().when(artifactProcessor).run();
-
- PowerMockito.mockStatic(ArtifactProcessorFactory.class);
- PowerMockito.when(ArtifactProcessorFactory.getArtifactProcessor((IDistributionClient)Matchers.anyObject(), (EventSender)Matchers.anyObject(),
- (INotificationData)Matchers.anyObject(), (IResourceInstance)Matchers.anyObject(),
- (IArtifactInfo)Matchers.anyObject(), (URI)Matchers.anyObject())).thenReturn(artifactProcessor);
+ //PowerMockito.mockStatic(ArtifactProcessorFactory.class);
+ ArtifactProcessorFactory artifactProcessorFactory=PowerMockito.mock(ArtifactProcessorFactory.class);
+ PowerMockito.when(artifactProcessorFactory.getArtifactProcessor(anyObject(), anyObject(),
+ anyObject(), anyObject(),
+ anyObject(), anyObject())).thenReturn(artifactProcessor);
Whitebox.setInternalState(sdcCallback,"eventSender", eventSender);
- PowerMockito.doReturn(readDownloadResult()).when(client).download((IArtifactInfo) Matchers.anyObject());
- PowerMockito.doReturn(null).when(client).sendDownloadStatus((IDistributionStatusMessage) Matchers.anyObject());
+ PowerMockito.doReturn(readDownloadResult()).when(client).download(anyObject());
+ PowerMockito.doReturn(null).when(client).sendDownloadStatus(anyObject());
- PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(Matchers.anyString(),Matchers.anyString(),Matchers.anyString());
+ PowerMockito.doReturn(null).when(storageService).retrieveSDCArtifact(Matchers.anyString(),
+ Matchers.anyString(),Matchers.anyString());
- PowerMockito.doAnswer(new Answer<Object>() {
- @Override
- public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
- System.out.print(invocationOnMock.getArguments()[0].toString());
- return null;
- }
- }).when(storageService).storeSDCArtifact((SDCArtifact)Matchers.anyObject());
+ PowerMockito.doAnswer(invocationOnMock -> {
+ System.out.print(invocationOnMock.getArguments()[0].toString());
+ return null;
+ }).when(storageService).storeSDCArtifact(anyObject());
}
private IDistributionClientDownloadResult readDownloadResult() throws IOException, URISyntaxException {
- DistributionClientDownloadResultImpl downloadResult = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS,"Download success");
+ DistributionClientDownloadResultImpl downloadResult = new DistributionClientDownloadResultImpl
+ (DistributionActionResultEnum.SUCCESS,"Download success");
File file = new File(this.getClass().getResource("/csar/service-ServiceAppc-csar.csar").toURI());
byte[] bFile = new byte[(int) file.length()];
}
-// @Test
+ @Test
public void testSDCListener() throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
-
-
INotificationData notificationData = getNotificationData();
sdcCallback.activateCallback(notificationData);
+ pause();
+ }
+
+ @Test
+ public void testArtifacts() throws Exception {
+ PowerMockito.doAnswer(invocationOnMock -> {
+ SDCArtifact artifact =(SDCArtifact)invocationOnMock.getArguments()[0];
+ SDCReference reference=(SDCReference)invocationOnMock.getArguments()[1];
+ Assert.assertEquals("abcd-efgh-ijkl",artifact.getArtifactUUID());
+ Assert.assertEquals("Resource-APPC",reference.getVnfType());
+ Assert.assertEquals(resourceContent.trim(),artifact.getArtifactContent().replaceAll(System.lineSeparator(),""));
+ return null;
+ }).doAnswer(invocation -> {
+ SDCArtifact artifact =(SDCArtifact)invocation.getArguments()[0];
+ SDCReference reference=(SDCReference)invocation.getArguments()[1];
+ Assert.assertEquals("Resource-APPC",reference.getVnfType());
+ Assert.assertEquals("tosca_dependency_model",reference.getFileCategory());
+ Assert.assertEquals("Dependency_model",artifact.getArtifactContent());
+ Assert.assertEquals("Resource-APPC",artifact.getResourceName());
+ return null;
+ }).when(storageService).storeSDCArtifactWithReference(anyObject(),anyObject());
+
+ artifactProcessor.processArtifact(readDownloadResult());
+ }
-// pause();
+ private void pause(){
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
}
-// private void pause(){
-// try {
-// Thread.sleep(50000000);
-// } catch (InterruptedException e) {
-// e.printStackTrace();
-// }
-// }
+ private String readInput(String inputFile) throws URISyntaxException {
+ File file = new File(this.getClass().getResource(inputFile).toURI());
+ byte[] bFile = new byte[(int) file.length()];
+ try(FileInputStream fileInputStream = new FileInputStream(file)){
+ fileInputStream.read(bFile);
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ return new String(bFile);
+ }
private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
}
private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
- Constructor constructor = Class.forName(fqcn).getDeclaredConstructors()[0];
+ Constructor constructor = Arrays.asList(Class.forName(fqcn).getDeclaredConstructors())
+ .stream()
+ .filter(constructor1 -> constructor1.getParameterCount()==0)
+ .collect(Collectors.toList())
+ .get(0);
constructor.setAccessible(true);
return constructor.newInstance();
}
public void testStopStartThread() throws Exception {
// null case
sdcListener.stopStartThread(123);
- Mockito.verify(mockLogger, times(0)).debug(String.valueOf(any()));
+ //Mockito.verify(mockLogger, times(0)).debug(String.valueOf(any()));
MockThread mockThread = spy(new MockThread());
mockThread.setNewState(Thread.State.TERMINATED);
sdcListener.stopStartThread(123);
Mockito.verify(mockThread, times(0)).interrupt();
- Mockito.verify(mockLogger, times(1)).debug(String.valueOf(any()));
+ //Mockito.verify(mockLogger, times(1)).debug(String.valueOf(any()));
Assert.assertTrue("Should reset startThread",
Whitebox.getInternalState(sdcListener, "startThread") == null);
mockThread.setNewState(state);
sdcListener.stopStartThread(123);
Mockito.verify(mockThread, times(++ timesCallThread)).interrupt();
- Mockito.verify(mockLogger, times(timesCallLogger += 2)).debug(String.valueOf(any()));
+ //Mockito.verify(mockLogger, times(timesCallLogger += 2)).debug(String.valueOf(any()));
Assert.assertTrue("Should reset startThread",
Whitebox.getInternalState(sdcListener, "startThread") == null);
}
--- /dev/null
+package org.openecomp.appc.sdc.listener;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.sdc.artifacts.object.Vnfc;
+
+public class SdcTestObjects {
+
+ @Test
+ public void testVnfcInstance(){
+ Vnfc vnfc=new Vnfc();
+ vnfc.setVnfcType("Firewall");
+ vnfc.setMandatory(true);
+ vnfc.setResilienceType("Active");
+ Assert.assertEquals("Firewall",vnfc.getVnfcType());
+ Assert.assertEquals(true,vnfc.isMandatory());
+ Assert.assertEquals("Active",vnfc.getResilienceType());
+ }
+
+
+}
--- /dev/null
+package org.openecomp.appc.sdc.listener;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
+import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class SdcTestUtils {
+
+ @Test
+ public void testToSdcStoreDocumentInput() throws Exception{
+ Assert.assertEquals(readInput("/output/TestUtilResponse.json"), Util.toSdcStoreDocumentInput
+ (getNotificationData(),getResources(),getServiceArtifact(),"Mock data"));
+ }
+
+ @Test
+ public void testProviderResponse(){
+ ProviderResponse response=new ProviderResponse(200,"Success");
+ Assert.assertEquals(200,response.getStatus());
+ Assert.assertEquals("Success",response.getBody());
+ }
+
+ private INotificationData getNotificationData() throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
+
+ INotificationData notificationData = (INotificationData)getObject("org.openecomp.sdc.impl.NotificationDataImpl");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+
+ invokeMethod(notificationData, "setServiceArtifacts", serviceArtifacts);
+ invokeMethod(notificationData,"setServiceUUID","4564-4567-7897");
+ invokeMethod(notificationData,"setDistributionID","Distribution ID Mock");
+ invokeMethod(notificationData,"setServiceDescription","Service Description Mock");
+ invokeMethod(notificationData,"setServiceName","Service Name Mock");
+
+ return notificationData;
+ }
+
+ private IResourceInstance getResources() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ IResourceInstance resource = (IResourceInstance)getObject("org.openecomp.sdc.impl.JsonContainerResourceInstance");
+
+ List<IArtifactInfo> serviceArtifacts = getServiceArtifacts();
+ invokeMethod(resource,"setArtifacts",serviceArtifacts);
+ invokeMethod(resource,"setResourceName","Vnf");
+ invokeMethod(resource,"setResourceVersion","1.0");
+ invokeMethod(resource,"setResourceUUID","Resource UUID");
+
+ return resource;
+ }
+
+ private void invokeMethod(Object object, String methodName,Object... arguments) throws IllegalAccessException, InvocationTargetException {
+ Method[] methods = object.getClass().getDeclaredMethods();
+ for(Method method:methods){
+ if(methodName.equalsIgnoreCase(method.getName())){
+ method.setAccessible(true);
+ method.invoke(object,arguments);
+ }
+ }
+ }
+ private Object getObject(String fqcn) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ Constructor constructor = Arrays.asList(Class.forName(fqcn).getDeclaredConstructors())
+ .stream()
+ .filter(constructor1 -> constructor1.getParameterCount()==0)
+ .collect(Collectors.toList())
+ .get(0);
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+ private List<IArtifactInfo> getServiceArtifacts() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ List<IArtifactInfo> serviceArtifacts = new ArrayList<>();
+ IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo,"setArtifactType","TOSCA_CSAR");
+ invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ serviceArtifacts.add(artifactInfo);
+ return serviceArtifacts;
+ }
+ private IArtifactInfo getServiceArtifact() throws ClassNotFoundException, InvocationTargetException,
+ InstantiationException, IllegalAccessException {
+ IArtifactInfo artifactInfo = (IArtifactInfo)getObject("org.openecomp.sdc.impl.ArtifactInfoImpl");
+ invokeMethod(artifactInfo,"setArtifactType","TOSCA_CSAR");
+ invokeMethod(artifactInfo,"setArtifactUUID","abcd-efgh-ijkl");
+ return artifactInfo;
+ }
+ private String readInput(String inputFile) throws URISyntaxException {
+ File file = new File(this.getClass().getResource(inputFile).toURI());
+ byte[] bFile = new byte[(int) file.length()];
+ try(FileInputStream fileInputStream = new FileInputStream(file)){
+ fileInputStream.read(bFile);
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ return new String(bFile);
+ }
+}
--- /dev/null
+{"input": {"document-parameters":{"service-name":"Service Name Mock","service-uuid":"4564-4567-7897","artifact-uuid":"abcd-efgh-ijkl","resource-version":"1.0","artifact-type":"TOSCA_CSAR","service-artifacts":"[]","service-description":"Service Description Mock","resource-uuid":"Resource UUID","resource-name":"Vnf","artifact-contents":"Mock data","distribution-id":"Distribution ID Mock"},"request-information":{"request-action":"StoreSdcDocumentRequest","source":"SDC","request-id":"4564-4567-7897"}}}
\ No newline at end of file
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0metadata: invariantUUID: 1f4f4e0e-a607-47a3-87b6-8d9a57007044 UUID: add63ad1-c6fe-4807-bdcf-a4b612b85a7a name: Resource-APPC description: desc type: VF category: Application L4+ subcategory: Media Servers resourceVendor: Vendor-1 resourceVendorRelease: '12345'imports:- Resource-APPC-interface: file: resource-ResourceAppc-template-interface.yml- NovaServer: file: resource-Novaserver-template.ymltopology_template: node_templates: NovaServer 1: type: org.openecomp.resource.vfc.nodes.heat.nova.Server metadata: invariantUUID: 28146796-4a0e-4e1e-bbd5-e1c87ec7a6cb UUID: cf7b9556-a7ed-421a-b611-6bd64b4aa6df customizationUUID: 0295fd77-0e14-4dd3-9a01-c00082694b88 version: '1.0' name: NovaServer description: Represents a real or virtual machine or server. Information specified on the Compute node will be used to find the machine that fits the given requirements in the cloud available machines. If no sizing information are specified the cloud provider default machine will be used. It is strongly recommended to specify the required CPUs and memory at least. type: VFC category: Generic subcategory: Infrastructure properties: image_update_policy: REBUILD software_config_transport: POLL_SERVER_CFN contrail_service_instance_ind: false user_data_format: HEAT_CFNTOOLS user_data_update_policy: REPLACE flavor_update_policy: RESIZE groups: { } substitution_mappings: node_type: org.openecomp.resource.vf.ResourceAppc capabilities: novaserver1.disk.device.write.bytes: - NovaServer 1 - disk.device.write.bytes novaserver1.memory.usage: - NovaServer 1 - memory.usage novaserver1.instance: - NovaServer 1 - instance novaserver1.scalable: - NovaServer 1 - scalable novaserver1.disk.usage: - NovaServer 1 - disk.usage novaserver1.disk.device.write.requests: - NovaServer 1 - disk.device.write.requests novaserver1.cpu.delta: - NovaServer 1 - cpu.delta novaserver1.disk.device.read.bytes: - NovaServer 1 - disk.device.read.bytes novaserver1.disk.write.requests.rate: - NovaServer 1 - disk.write.requests.rate novaserver1.disk.iops: - NovaServer 1 - disk.iops novaserver1.disk.latency: - NovaServer 1 - disk.latency novaserver1.cpu: - NovaServer 1 - cpu novaserver1.feature: - NovaServer 1 - feature novaserver1.host: - NovaServer 1 - host novaserver1.disk.write.bytes: - NovaServer 1 - disk.write.bytes novaserver1.disk.device.usage: - NovaServer 1 - disk.device.usage novaserver1.disk.device.write.bytes.rate: - NovaServer 1 - disk.device.write.bytes.rate novaserver1.disk.device.write.requests.rate: - NovaServer 1 - disk.device.write.requests.rate novaserver1.vcpus: - NovaServer 1 - vcpus novaserver1.binding: - NovaServer 1 - binding novaserver1.disk.write.bytes.rate: - NovaServer 1 - disk.write.bytes.rate novaserver1.disk.device.allocation: - NovaServer 1 - disk.device.allocation novaserver1.disk.device.read.bytes.rate: - NovaServer 1 - disk.device.read.bytes.rate novaserver1.memory.resident: - NovaServer 1 - memory.resident novaserver1.disk.read.requests: - NovaServer 1 - disk.read.requests novaserver1.disk.read.bytes.rate: - NovaServer 1 - disk.read.bytes.rate novaserver1.disk.capacity: - NovaServer 1 - disk.capacity novaserver1.memory: - NovaServer 1 - memory novaserver1.cpu_util: - NovaServer 1 - cpu_util novaserver1.os: - NovaServer 1 - os novaserver1.disk.allocation: - NovaServer 1 - disk.allocation novaserver1.disk.device.latency: - NovaServer 1 - disk.device.latency novaserver1.endpoint: - NovaServer 1 - endpoint novaserver1.disk.root.size: - NovaServer 1 - disk.root.size novaserver1.disk.device.iops: - NovaServer 1 - disk.device.iops novaserver1.disk.device.capacity: - NovaServer 1 - disk.device.capacity novaserver1.disk.device.read.requests: - NovaServer 1 - disk.device.read.requests novaserver1.disk.write.requests: - NovaServer 1 - disk.write.requests novaserver1.disk.ephemeral.size: - NovaServer 1 - disk.ephemeral.size novaserver1.disk.device.read.requests.rate: - NovaServer 1 - disk.device.read.requests.rate novaserver1.disk.read.bytes: - NovaServer 1 - disk.read.bytes requirements: novaserver1.dependency: - NovaServer 1 - dependency novaserver1.local_storage: - NovaServer 1 - local_storage
\ No newline at end of file