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 static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.nullValue;
27 import static org.hamcrest.MatcherAssert.assertThat;
29 import java.util.HashMap;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
34 import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
36 public class DistributionStatusInfoTest {
38 private static final String AUDIT_DISTRIBUTION_STATUS_TIME = "AUDIT_DISTRIBUTION_STATUS_TIME";
39 private static final String AUDIT_DISTRIBUTION_CONSUMER_ID = "AUDIT_DISTRIBUTION_CONSUMER_ID";
40 private static final String AUDIT_DISTRIBUTION_RESOURCE_URL = "AUDIT_DISTRIBUTION_RESOURCE_URL";
41 private static final String AUDIT_STATUS = "AUDIT_STATUS";
42 private static final String AUDIT_DESC = "AUDIT_DESC";
45 public void shouldHaveValidGettersAndSetters() {
46 assertThat(DistributionStatusInfo.class, hasValidGettersAndSetters());
50 public void testCtorWithESTimeBasedEvent() {
51 ESTimeBasedEvent distributionStatusEvent = createESTimeBasedEvent();
52 DistributionStatusInfo distributionStatusInfo = new DistributionStatusInfo(distributionStatusEvent);
53 Assert.assertThat(distributionStatusInfo.getTimestamp(), is(AUDIT_DISTRIBUTION_STATUS_TIME));
54 Assert.assertThat(distributionStatusInfo.getOmfComponentID(), is(AUDIT_DISTRIBUTION_CONSUMER_ID));
55 Assert.assertThat(distributionStatusInfo.getErrorReason(), is(AUDIT_DESC));
56 Assert.assertThat(distributionStatusInfo.getStatus(), is(AUDIT_STATUS));
57 Assert.assertThat(distributionStatusInfo.getUrl(), is(AUDIT_DISTRIBUTION_RESOURCE_URL));
61 public void shouldTestWhetherTheDefaultConstructorCorrectlySetAllFields() {
62 DistributionStatusInfo distributionStatusInfo = new DistributionStatusInfo(AUDIT_DISTRIBUTION_CONSUMER_ID, AUDIT_DISTRIBUTION_STATUS_TIME, AUDIT_DISTRIBUTION_RESOURCE_URL, AUDIT_STATUS);
63 Assert.assertThat(distributionStatusInfo.getUrl(), is(AUDIT_DISTRIBUTION_RESOURCE_URL));
64 Assert.assertThat(distributionStatusInfo.getStatus(), is(AUDIT_STATUS));
65 Assert.assertThat(distributionStatusInfo.getOmfComponentID(), is(AUDIT_DISTRIBUTION_CONSUMER_ID));
66 Assert.assertThat(distributionStatusInfo.getTimestamp(), is(AUDIT_DISTRIBUTION_STATUS_TIME));
69 private ESTimeBasedEvent createESTimeBasedEvent() {
70 ESTimeBasedEvent distributionStatusEvent = new ESTimeBasedEvent();
71 Map<String, Object> fields = new HashMap<>();
72 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), AUDIT_DISTRIBUTION_CONSUMER_ID);
73 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName(), AUDIT_DISTRIBUTION_STATUS_TIME);
74 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), AUDIT_DISTRIBUTION_RESOURCE_URL);
75 fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), AUDIT_STATUS);
76 fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), AUDIT_DESC);
77 distributionStatusEvent.setFields(fields);
78 return distributionStatusEvent;