Some unit tests for catalog-be
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / info / DistributionStatusInfoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  * ================================================================================
21  */
22 package org.openecomp.sdc.be.info;
23
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;
28
29 import java.util.HashMap;
30 import java.util.Map;
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;
35
36 public class DistributionStatusInfoTest {
37
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";
43
44         @Test
45         public void shouldHaveValidGettersAndSetters() {
46                 assertThat(DistributionStatusInfo.class, hasValidGettersAndSetters());
47         }
48
49         @Test
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));
58         }
59
60         @Test
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));
67         }
68
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;
79         }
80
81 }