summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java400
1 files changed, 312 insertions, 88 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java
index 7ecd069448..f3fa747901 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentsUtilsTest.java
@@ -1,45 +1,5 @@
package org.openecomp.sdc.be.components.impl;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.ARTIFACT_DATA;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.ARTIFACT_UUID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.COMMENT;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.CURRENT_STATE;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.CURRENT_VERSION;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DCURR_STATUS;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DESCRIPTION;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DESC_ERROR;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DIST_CONSUMER_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DIST_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DIST_RESOURCE_URL;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.DPREV_STATUS;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.INVARIANT_UUID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.MODIFIER_FIRST_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.MODIFIER_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.MODIFIER_LAST_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.MODIFIER_UID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.OP_ENV_ACTION;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.OP_ENV_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.OP_ENV_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.OP_ENV_TYPE;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.PREV_RESOURCE_STATE;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.PREV_RESOURCE_VERSION;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.REQUEST_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.RESOURCE_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.SERVICE_INSTANCE_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.STATUS_500;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.STATUS_OK;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.TENANT_CONTEXT;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.TESTER_USER_ROLE;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.TOSCA_NODE_TYPE;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.UPDATED_USER_EXTENDED_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.USER_EMAIL;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.USER_FIRST_NAME;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.USER_ID;
-import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.USER_LAST_NAME;
-
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -50,26 +10,27 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
-import org.openecomp.sdc.be.auditing.impl.AuditBaseEventFactory;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.DistributionDownloadEvent;
-import org.openecomp.sdc.be.resources.data.auditing.EcompOperationalEnvironmentEvent;
-import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
-import org.openecomp.sdc.be.resources.data.auditing.UserAdminEvent;
+import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.resources.data.auditing.*;
import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceAuditData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.exception.ResponseFormat;
+import javax.servlet.http.HttpServletRequest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.auditing.impl.AuditTestUtils.*;
+
@RunWith(MockitoJUnitRunner.class)
public class ComponentsUtilsTest {
@@ -79,12 +40,15 @@ public class ComponentsUtilsTest {
@Mock
private AuditingManager manager;
-
@Mock
private ResponseFormat responseFormat;
+ @Mock
+ private HttpServletRequest request;
+
+ private ArtifactDefinition artifactDefinition = null;
@Captor
- private ArgumentCaptor<AuditBaseEventFactory> factoryCaptor;
+ private ArgumentCaptor<AuditEventFactory> factoryCaptor;
@InjectMocks
private static ComponentsUtils utils;
@@ -110,20 +74,21 @@ public class ComponentsUtilsTest {
service.setUUID(SERVICE_INSTANCE_ID);
service.setInvariantUUID(INVARIANT_UUID);
- utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.ARTIFACT_DELETE, service.getComponentType(),
- ResourceAuditData.newBuilder()
+ utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.ARTIFACT_DELETE,
+ new ResourceCommonInfo(RESOURCE_NAME, service.getComponentType().getValue()),
+ ResourceVersionInfo.newBuilder()
.state(PREV_RESOURCE_STATE)
.version(PREV_RESOURCE_VERSION)
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DPREV_STATUS).build(),
- ResourceAuditData.newBuilder()
+ ResourceVersionInfo.newBuilder()
.state(CURRENT_STATE)
.version(CURRENT_VERSION)
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DCURR_STATUS).build(),
- RESOURCE_NAME, COMMENT, ARTIFACT_DATA, DIST_ID);
+ COMMENT, artifactDefinition, DIST_ID);
verifyResourceAdminEvent(AuditingActionEnum.ARTIFACT_DELETE.getName(), STATUS_OK, DESCRIPTION, service.getComponentType().getValue(),
- false, true, true, true, true, true);
+ false, true, true, false, true, true, true);
}
@Test
@@ -135,18 +100,19 @@ public class ComponentsUtilsTest {
service.setInvariantUUID(INVARIANT_UUID);
service.setState(LifecycleStateEnum.CERTIFIED);
service.setVersion(CURRENT_VERSION);
- utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.CREATE_RESOURCE, service.getComponentType(),
- ResourceAuditData.newBuilder()
+ utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.CREATE_RESOURCE,
+ new ResourceCommonInfo(RESOURCE_NAME, service.getComponentType().getValue()),
+ ResourceVersionInfo.newBuilder()
.state(PREV_RESOURCE_STATE)
.version(PREV_RESOURCE_VERSION)
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DPREV_STATUS).build(),
- ResourceAuditData.newBuilder()
+ ResourceVersionInfo.newBuilder()
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DCURR_STATUS).build(),
- RESOURCE_NAME, COMMENT, ARTIFACT_DATA, DIST_ID);
+ COMMENT, artifactDefinition, DIST_ID);
verifyResourceAdminEvent(AuditingActionEnum.CREATE_RESOURCE.getName(), STATUS_OK, DESCRIPTION, service.getComponentType().getValue(),
- false, true, true, true, true, true);
+ false, true, true, false, true, true, true);
}
@@ -160,18 +126,19 @@ public class ComponentsUtilsTest {
service.setState(LifecycleStateEnum.CERTIFIED);
service.setName(RESOURCE_NAME);
service.setVersion(CURRENT_VERSION);
- utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST, service.getComponentType(),
- ResourceAuditData.newBuilder()
+ utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST,
+ new ResourceCommonInfo(service.getComponentType().getValue()),
+ ResourceVersionInfo.newBuilder()
.state(PREV_RESOURCE_STATE)
.version(PREV_RESOURCE_VERSION)
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DPREV_STATUS).build(),
- ResourceAuditData.newBuilder()
+ ResourceVersionInfo.newBuilder()
.artifactUuid(ARTIFACT_UUID)
.distributionStatus(DCURR_STATUS).build());
verifyResourceAdminEvent(AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(),
STATUS_OK, DESCRIPTION, service.getComponentType().getValue(),
- false, true, true, false, false, true);
+ false, true, true, false, false, true, false);
}
@Test
@@ -186,10 +153,10 @@ public class ComponentsUtilsTest {
service.setVersion(CURRENT_VERSION);
utils.auditComponent(responseFormat, modifier, service, AuditingActionEnum.CERTIFICATION_REQUEST_RESOURCE,
- ComponentTypeEnum.SERVICE,
- ResourceAuditData.newBuilder().state(PREV_RESOURCE_STATE).version(PREV_RESOURCE_VERSION).artifactUuid(ARTIFACT_UUID).build());
+ new ResourceCommonInfo(ComponentTypeEnum.SERVICE.getValue()),
+ ResourceVersionInfo.newBuilder().state(PREV_RESOURCE_STATE).version(PREV_RESOURCE_VERSION).artifactUuid(ARTIFACT_UUID).build());
verifyResourceAdminEvent(AuditingActionEnum.CERTIFICATION_REQUEST_RESOURCE.getName(), STATUS_500, DESC_ERROR,
- service.getComponentType().getValue(), false, true, false, false, false, false);
+ service.getComponentType().getValue(), false, true, false, false, false, false, false);
}
@Test
@@ -198,9 +165,9 @@ public class ComponentsUtilsTest {
when(responseFormat.getFormattedMessage()).thenReturn(DESC_ERROR);
utils.auditComponent(responseFormat, modifier, AuditingActionEnum.START_CERTIFICATION_RESOURCE,
- RESOURCE_NAME, ComponentTypeEnum.SERVICE, COMMENT);
+ new ResourceCommonInfo(RESOURCE_NAME, ComponentTypeEnum.SERVICE.getValue()), COMMENT);
verifyResourceAdminEvent(AuditingActionEnum.START_CERTIFICATION_RESOURCE.getName(), STATUS_500, DESC_ERROR, service.getComponentType().getValue(),
- true, false, false, false, true, false);
+ true, false, false, false, true, false, false);
}
@Test
@@ -215,7 +182,7 @@ public class ComponentsUtilsTest {
service.setVersion(CURRENT_VERSION);
utils.auditComponentAdmin(responseFormat, modifier, service, AuditingActionEnum.CREATE_RESOURCE, service.getComponentType());
verifyResourceAdminEvent(AuditingActionEnum.CREATE_RESOURCE.getName(), STATUS_500, DESC_ERROR, service.getComponentType().getValue(),
- false, false, false, false, false, false);
+ false, false, false, false, false, false, false);
}
@Test
@@ -230,14 +197,14 @@ public class ComponentsUtilsTest {
resource.setVersion(CURRENT_VERSION);
resource.setToscaResourceName(TOSCA_NODE_TYPE);
utils.auditResource(responseFormat, modifier, resource, null, AuditingActionEnum.IMPORT_RESOURCE,
- ResourceAuditData.newBuilder()
+ ResourceVersionInfo.newBuilder()
.state(PREV_RESOURCE_STATE)
.version(PREV_RESOURCE_VERSION)
.artifactUuid(ARTIFACT_UUID)
.build(),
- ARTIFACT_UUID, ARTIFACT_DATA);
+ ARTIFACT_UUID, artifactDefinition);
verifyResourceAdminEvent(AuditingActionEnum.IMPORT_RESOURCE.getName(), STATUS_OK, DESCRIPTION, resource.getResourceType().name(),
- false, true, true, true, false, false);
+ false, true, true, false, false, false, false);
}
@Test
@@ -253,7 +220,7 @@ public class ComponentsUtilsTest {
utils.auditResource(responseFormat, modifier, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
verifyResourceAdminEvent(AuditingActionEnum.UPDATE_RESOURCE_METADATA.getName(), STATUS_500, DESC_ERROR, resource.getResourceType().name(),
- false, false, false, false, false, false);
+ false, false, false, false, false, false, false);
}
@Test
@@ -263,7 +230,7 @@ public class ComponentsUtilsTest {
utils.auditResource(responseFormat, modifier, RESOURCE_NAME, AuditingActionEnum.CHECKOUT_RESOURCE);
verifyResourceAdminEvent(AuditingActionEnum.CHECKOUT_RESOURCE.getName(), STATUS_500, DESC_ERROR, ComponentTypeEnum.RESOURCE.getValue(),
- true, false, false, false, false, false);
+ true, false, false, false, false, false, false);
}
@Test
@@ -325,7 +292,7 @@ public class ComponentsUtilsTest {
private void verifyResourceAdminEvent(String action, String status, String desc, String resourceType, boolean isComponentNull,
boolean isPrevStateAndVersionSet, boolean isCurrFieldsProvided, boolean isArtDataProvided, boolean isCommentProvided,
- boolean isDistStatusProvided) {
+ boolean isDistStatusProvided, boolean isDidProvided) {
verify(manager).auditEvent(factoryCaptor.capture());
AuditEventFactory factory = factoryCaptor.getValue();
ResourceAdminEvent event = (ResourceAdminEvent)factory.getDbEvent();
@@ -373,15 +340,14 @@ public class ComponentsUtilsTest {
}
if (isArtDataProvided) {
assertThat(event.getArtifactData()).isEqualTo(ARTIFACT_DATA);
- if (resourceType.equals(ResourceTypeEnum.VFC.name())) {
- assertThat(event.getDid()).isNull();
- }
- else {
- assertThat(event.getDid()).isEqualTo(DIST_ID);
- }
}
else {
- assertThat(event.getArtifactData()).isNull();
+ assertThat(event.getArtifactData()).isEmpty();
+ }
+ if (isDidProvided) {
+ assertThat(event.getDid()).isEqualTo(DIST_ID);
+ }
+ else {
assertThat(event.getDid()).isNull();
}
if (isCommentProvided) {
@@ -399,4 +365,262 @@ public class ComponentsUtilsTest {
assertThat(event.getDprevStatus()).isNull();
}
}
+
+ @Test
+ public void auditChangeLifeCycleExternalApiEventWhenComponentAndResponseObjectAreNull() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_500));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESC_ERROR);
+
+ utils.auditChangeLifecycleAction(responseFormat, ComponentTypeEnum.RESOURCE, REQUEST_ID,
+ null, null, new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), modifier);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditChangeLifecycleExternalApiEventFactory factory = (AuditChangeLifecycleExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ assertThat(event.getAction()).isEqualTo(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getName());
+ verifyCommonDataForExternalApiEvent(event, false);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyCurrentResourceVersionInfoForExternalApiEvent(event, true);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEqualTo(MODIFIER_UID);
+ assertThat(event.getInvariantUuid()).isEmpty();
+ assertThat(event.getResourceName()).isNull();
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void auditChangeLifeCycleExternalApiEventWhenComponentIsNullAndResponseObjectIsNotNull() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_OK));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESCRIPTION);
+ Component responseObject = new Resource();
+ responseObject.setVersion(CURRENT_VERSION);
+ responseObject.setState(LifecycleStateEnum.CERTIFIED);
+ responseObject.setInvariantUUID(INVARIANT_UUID);
+ responseObject.setUUID(SERVICE_INSTANCE_ID);
+
+ utils.auditChangeLifecycleAction(responseFormat, ComponentTypeEnum.RESOURCE, REQUEST_ID,
+ null, responseObject, new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), modifier);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditChangeLifecycleExternalApiEventFactory factory = (AuditChangeLifecycleExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ assertThat(event.getAction()).isEqualTo(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getName());
+ verifyCommonDataForExternalApiEvent(event, true);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyCurrentResourceVersionInfoForExternalApiEvent(event, false);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEqualTo(MODIFIER_UID);
+ assertThat(event.getInvariantUuid()).isEqualTo(INVARIANT_UUID);
+ assertThat(event.getResourceName()).isNull();
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void auditChangeLifeCycleExternalApiEventWhenComponentIsNotNullAndResponseObjectIsNull() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_500));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESC_ERROR);
+ Component component = new Resource();
+ component.setVersion(PREV_RESOURCE_VERSION);
+ component.setState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ component.setInvariantUUID(INVARIANT_UUID);
+ component.setName(RESOURCE_NAME);
+
+ utils.auditChangeLifecycleAction(responseFormat, ComponentTypeEnum.RESOURCE, REQUEST_ID,
+ component, null, new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), modifier);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditChangeLifecycleExternalApiEventFactory factory = (AuditChangeLifecycleExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ assertThat(event.getAction()).isEqualTo(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getName());
+
+ verifyCommonDataForExternalApiEvent(event, false);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, false);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEqualTo(MODIFIER_UID);
+ assertThat(event.getInvariantUuid()).isEqualTo(INVARIANT_UUID);
+ assertThat(event.getResourceName()).isEqualTo(RESOURCE_NAME);
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void auditChangeLifeCycleExternalApiEventWhenComponentAndResponseObjectAreNotNull() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_OK));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESCRIPTION);
+ Component responseObject = new Resource();
+ responseObject.setVersion(CURRENT_VERSION);
+ responseObject.setState(LifecycleStateEnum.CERTIFIED);
+ responseObject.setInvariantUUID(INVARIANT_UUID);
+ responseObject.setUUID(SERVICE_INSTANCE_ID);
+
+ Component component = new Resource();
+ component.setVersion(PREV_RESOURCE_VERSION);
+ component.setState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ component.setInvariantUUID(INVARIANT_UUID);
+ component.setUUID(SERVICE_INSTANCE_ID);
+ component.setName(RESOURCE_NAME);
+
+ utils.auditChangeLifecycleAction(responseFormat, ComponentTypeEnum.RESOURCE, REQUEST_ID,
+ null, responseObject, new DistributionData(DIST_CONSUMER_ID, DIST_RESOURCE_URL), modifier);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditChangeLifecycleExternalApiEventFactory factory = (AuditChangeLifecycleExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ assertThat(event.getAction()).isEqualTo(AuditingActionEnum.CHANGE_LIFECYCLE_BY_API.getName());
+ verifyCommonDataForExternalApiEvent(event, true);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyCurrentResourceVersionInfoForExternalApiEvent(event, false);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEqualTo(MODIFIER_UID);
+ assertThat(event.getInvariantUuid()).isEqualTo(INVARIANT_UUID);
+ assertThat(event.getResourceName()).isNull();
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+
+ }
+
+ private void verifyDistributionDataForExternalApiEvent(ExternalApiEvent event) {
+ assertThat(event.getConsumerId()).isEqualTo(DIST_CONSUMER_ID);
+ assertThat(event.getResourceURL()).isEqualTo(DIST_RESOURCE_URL);
+ }
+
+ private void verifyDistributionDataNotSetForExternalApiEvent(ExternalApiEvent event) {
+ assertThat(event.getConsumerId()).isNull();
+ assertThat(event.getResourceURL()).isNull();
+ }
+
+ private void verifyCommonDataForExternalApiEvent(ExternalApiEvent event, boolean isSucceeded) {
+ if (isSucceeded) {
+ assertThat(event.getDesc()).isEqualTo(DESCRIPTION);
+ assertThat(event.getStatus()).isEqualTo(STATUS_OK);
+ assertThat(event.getServiceInstanceId()).isEqualTo(SERVICE_INSTANCE_ID);
+ }
+ else {
+ assertThat(event.getDesc()).isEqualTo(DESC_ERROR);
+ assertThat(event.getStatus()).isEqualTo(STATUS_500);
+ assertThat(event.getServiceInstanceId()).isNullOrEmpty();
+ }
+ assertThat(event.getRequestId()).isEqualTo(REQUEST_ID);
+ }
+
+ private void verifyCurrentResourceVersionInfoForExternalApiEvent(ExternalApiEvent event, boolean isNull) {
+ assertThat(event.getCurrArtifactUuid()).isNull();
+ if (isNull) {
+ assertThat(event.getCurrState()).isNull();
+ assertThat(event.getCurrVersion()).isNull();
+ }
+ else {
+ assertThat(event.getCurrState()).isEqualTo(LifecycleStateEnum.CERTIFIED.name());
+ assertThat(event.getCurrVersion()).isEqualTo(CURRENT_VERSION);
+ }
+ }
+
+ private void verifyPreviousResourceVersionInfoForExternalApiEvent(ExternalApiEvent event, boolean isNull) {
+ assertThat(event.getPrevArtifactUuid()).isNull();
+ if (isNull) {
+ assertThat(event.getPrevState()).isNull();
+ assertThat(event.getPrevVersion()).isNull();
+ }
+ else {
+ assertThat(event.getPrevState()).isEqualTo(LifecycleStateEnum.READY_FOR_CERTIFICATION.name());
+ assertThat(event.getPrevVersion()).isEqualTo(PREV_RESOURCE_VERSION);
+ }
+ }
+
+ @Test
+ public void auditExternalCreateResourceEventWhenResourceObjectIsNull() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_500));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESC_ERROR);
+
+ when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(USER_ID);
+ when(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER)).thenReturn(DIST_CONSUMER_ID);
+ when(request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER)).thenReturn(REQUEST_ID);
+ when(request.getRequestURI()).thenReturn(DIST_RESOURCE_URL);
+
+ utils.auditCreateResourceExternalApi(responseFormat, new ResourceCommonInfo(RESOURCE_NAME, ComponentTypeEnum.RESOURCE.getValue()),
+ request, null);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditCreateResourceExternalApiEventFactory factory = (AuditCreateResourceExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ verifyCommonDataForExternalApiEvent(event, false);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyCurrentResourceVersionInfoForExternalApiEvent(event, true);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEqualTo("(" + USER_ID + ")");
+ assertThat(event.getInvariantUuid()).isNull();
+ assertThat(event.getResourceName()).isEqualTo(RESOURCE_NAME);
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void auditExternalCreateResourceEventWhenResourceObjectIsNullAndRequestDataIsNotProvided() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_500));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESC_ERROR);
+
+ when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(null);
+ when(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER)).thenReturn(null);
+ when(request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER)).thenReturn(REQUEST_ID);
+ when(request.getRequestURI()).thenReturn(null);
+
+ utils.auditCreateResourceExternalApi(responseFormat, new ResourceCommonInfo(ComponentTypeEnum.RESOURCE.getValue()),
+ request, null);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditCreateResourceExternalApiEventFactory factory = (AuditCreateResourceExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ verifyCommonDataForExternalApiEvent(event, false);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyCurrentResourceVersionInfoForExternalApiEvent(event, true);
+ verifyDistributionDataNotSetForExternalApiEvent(event);
+ assertThat(event.getModifier()).isEmpty();
+ assertThat(event.getInvariantUuid()).isNull();
+ assertThat(event.getResourceName()).isNull();
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void auditExternalCreateResourceEventWhenResourceObjectAndRequestDataProvided() {
+ when(responseFormat.getStatus()).thenReturn(Integer.valueOf(STATUS_OK));
+ when(responseFormat.getFormattedMessage()).thenReturn(DESCRIPTION);
+
+ when(request.getHeader(Constants.USER_ID_HEADER)).thenReturn(USER_ID);
+ when(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER)).thenReturn(DIST_CONSUMER_ID);
+ when(request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER)).thenReturn(REQUEST_ID);
+ when(request.getRequestURI()).thenReturn(DIST_RESOURCE_URL);
+
+ Resource resource = new Resource();
+ resource.setName(RESOURCE_NAME);
+ resource.setInvariantUUID(INVARIANT_UUID);
+ resource.setUUID(SERVICE_INSTANCE_ID);
+
+ utils.auditCreateResourceExternalApi(responseFormat, new ResourceCommonInfo(ComponentTypeEnum.RESOURCE.getValue()),
+ request, resource);
+
+ verify(manager).auditEvent(factoryCaptor.capture());
+ AuditCreateResourceExternalApiEventFactory factory = (AuditCreateResourceExternalApiEventFactory)factoryCaptor.getValue();
+
+ ExternalApiEvent event = (ExternalApiEvent)factory.getDbEvent();
+ verifyCommonDataForExternalApiEvent(event, true);
+ verifyPreviousResourceVersionInfoForExternalApiEvent(event, true);
+ verifyDistributionDataForExternalApiEvent(event);
+ assertThat(event.getCurrArtifactUuid()).isNull();
+ assertThat(event.getCurrState()).isEqualTo(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ assertThat(event.getCurrVersion()).isEqualTo(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION);
+ assertThat(event.getModifier()).isEqualTo("(" + USER_ID + ")");
+ assertThat(event.getInvariantUuid()).isEqualTo(INVARIANT_UUID);
+ assertThat(event.getResourceName()).isEqualTo(RESOURCE_NAME);
+ assertThat(event.getResourceType()).isEqualTo(ComponentTypeEnum.RESOURCE.getValue());
+ }
+
+ @Test
+ public void checkIfAuditEventIsExternal() {
+ assertThat(utils.isExternalApiEvent(AuditingActionEnum.ARTIFACT_UPLOAD_BY_API)).isTrue();
+ assertThat(utils.isExternalApiEvent(AuditingActionEnum.ARTIFACT_UPLOAD)).isFalse();
+ }
+
}