1 package org.openecomp.sdc.enrichment.impl.external.artifact;
3 public class ProcessArtifactEnricherTest {
5 ProcessDao processDaoMock;
7 EnrichedServiceModelDao enrichedServiceModelDaoMock;
9 ComponentDao componentDaoMock;
11 ProcessArtifactEnricher processArtifactEnricher;
13 @BeforeMethod(alwaysRun = true)
14 public void injectDoubles() {
15 MockitoAnnotations.initMocks(this);
19 public void testEnrichComponent() throws Exception {
21 String componentId = "1111111111";
22 Version version = new Version();
26 ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId);
28 ProcessEntity entity = new ProcessEntity(vspId, version, componentId, null);
29 ProcessEntity processEntity = new ProcessEntity();
30 processEntity.setType(ProcessType.Lifecycle_Operations);
31 processEntity.setVspId(vspId);
32 processEntity.setVersion(version);
33 processEntity.setComponentId(componentId);
34 processEntity.setArtifactName("artifact_1kb.txt");
35 processEntity.setArtifact(getMibByteBuffer("/mock/enrichProcess/artifact_1kb.txt"));
37 Collection<ComponentEntity> componentList = new ArrayList<>();
38 componentList.add(componentEntity);
39 when(componentDaoMock.list(anyObject())).thenReturn(componentList);
41 Collection<ProcessEntity> list = new ArrayList<>();
42 list.add(processEntity);
43 when(processDaoMock.list(entity)).thenReturn(list);
45 when(processDaoMock.get(anyObject())).thenReturn(processEntity);
47 EnrichmentInfo info = new EnrichmentInfo();
48 info.setVersion(version);
50 processArtifactEnricher.enrich(info);
52 String componentName = componentEntity.getComponentCompositionData().getName();
54 ArgumentCaptor<ServiceArtifact> expectedServiceArtifact =
55 ArgumentCaptor.forClass(ServiceArtifact.class);
56 Mockito.verify(enrichedServiceModelDaoMock, atLeastOnce())
57 .storeExternalArtifact(expectedServiceArtifact.capture());
59 .assertEquals(expectedServiceArtifact.getValue().getName().startsWith(componentName), true);
60 Assert.assertEquals(expectedServiceArtifact.getValue().getName(),
61 componentName + File.separator + ArtifactCategory.DEPLOYMENT.getDisplayName() +
62 File.separator + "Lifecycle Operations" + File.separator + "artifact_1kb.txt");
66 private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) {
67 ComponentEntity componentEntity = new ComponentEntity();
68 componentEntity.setId(componentId);
69 componentEntity.setVspId(vspId);
70 componentEntity.setVersion(version);
72 String componentName = vspId + "enrichMib_server";
73 String compositionData = "{\n" +
74 " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentName + "\",\n" +
75 " \"displayName\": \"" + componentName + "\"\n" +
77 componentEntity.setCompositionData(compositionData);
78 return componentEntity;
81 private ByteBuffer getMibByteBuffer(String fileName) {
82 byte[] mibBytes = FileUtils.readViaInputStream(this.getClass().getResource(fileName),
83 stream -> FileUtils.toByteArray(stream));
84 return ByteBuffer.wrap(mibBytes);