2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.info;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
27 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
29 import java.util.HashMap;
32 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
33 import static org.hamcrest.CoreMatchers.is;
34 import static org.hamcrest.MatcherAssert.assertThat;
37 public class DistributionStatusInfoTest {
39 private static final String AUDIT_DISTRIBUTION_STATUS_TIME = "AUDIT_DISTRIBUTION_STATUS_TIME";
40 private static final String AUDIT_DISTRIBUTION_CONSUMER_ID = "AUDIT_DISTRIBUTION_CONSUMER_ID";
41 private static final String AUDIT_DISTRIBUTION_RESOURCE_URL = "AUDIT_DISTRIBUTION_RESOURCE_URL";
42 private static final String AUDIT_STATUS = "AUDIT_STATUS";
43 private static final String AUDIT_DESC = "AUDIT_DESC";
46 public void shouldHaveValidGettersAndSetters() {
47 assertThat(DistributionStatusInfo.class, hasValidGettersAndSetters());
51 public void testCtorWithAuditingGenericEvent() {
52 AuditingGenericEvent distributionStatusEvent = createAuditingGenericEvent();
53 DistributionStatusInfo distributionStatusInfo = new DistributionStatusInfo(distributionStatusEvent);
54 Assert.assertThat(distributionStatusInfo.getTimestamp(), is(AUDIT_DISTRIBUTION_STATUS_TIME));
55 Assert.assertThat(distributionStatusInfo.getOmfComponentID(), is(AUDIT_DISTRIBUTION_CONSUMER_ID));
56 Assert.assertThat(distributionStatusInfo.getErrorReason(), is(AUDIT_DESC));
57 Assert.assertThat(distributionStatusInfo.getStatus(), is(AUDIT_STATUS));
58 Assert.assertThat(distributionStatusInfo.getUrl(), is(AUDIT_DISTRIBUTION_RESOURCE_URL));
62 public void shouldTestWhetherTheDefaultConstructorCorrectlySetAllFields() {
63 DistributionStatusInfo distributionStatusInfo = new DistributionStatusInfo(AUDIT_DISTRIBUTION_CONSUMER_ID, AUDIT_DISTRIBUTION_STATUS_TIME, AUDIT_DISTRIBUTION_RESOURCE_URL, AUDIT_STATUS);
64 Assert.assertThat(distributionStatusInfo.getUrl(), is(AUDIT_DISTRIBUTION_RESOURCE_URL));
65 Assert.assertThat(distributionStatusInfo.getStatus(), is(AUDIT_STATUS));
66 Assert.assertThat(distributionStatusInfo.getOmfComponentID(), is(AUDIT_DISTRIBUTION_CONSUMER_ID));
67 Assert.assertThat(distributionStatusInfo.getTimestamp(), is(AUDIT_DISTRIBUTION_STATUS_TIME));
70 private AuditingGenericEvent createAuditingGenericEvent() {
71 AuditingGenericEvent distributionStatusEvent = new AuditingGenericEvent();
72 Map<String, Object> fields = new HashMap<>();
73 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), AUDIT_DISTRIBUTION_CONSUMER_ID);
74 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName(), AUDIT_DISTRIBUTION_STATUS_TIME);
75 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), AUDIT_DISTRIBUTION_RESOURCE_URL);
76 fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), AUDIT_STATUS);
77 fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), AUDIT_DESC);
78 distributionStatusEvent.setFields(fields);
79 return distributionStatusEvent;