cleaned up clds service code
[clamp.git] / src / test / java / org / onap / clamp / clds / model / CldsDbServiceCacheTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * Modifications copyright (c) 2018 Nokia
21  * ===================================================================
22  * 
23  */
24
25 package org.onap.clamp.clds.model;
26
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotNull;
30
31 import java.io.IOException;
32 import java.io.ObjectInputStream;
33 import java.util.ArrayList;
34 import java.util.List;
35 import org.junit.Test;
36
37 public class CldsDbServiceCacheTest {
38
39     @Test
40     public void testConstructor() throws IOException, ClassNotFoundException {
41         // given
42         CldsServiceData cldsServiceData = new CldsServiceData();
43         cldsServiceData.setServiceUUID("testUUID");
44         cldsServiceData.setAgeOfRecord(100L);
45         cldsServiceData.setServiceInvariantUUID("testInvariantUUID");
46
47         CldsVfData cldsVfData = new CldsVfData();
48         cldsVfData.setVfName("vf");
49
50         CldsVfKPIData cldsVfKpiData = new CldsVfKPIData();
51         cldsVfKpiData.setFieldPath("fieldPath");
52         cldsVfKpiData.setFieldPathValue("fieldValue");
53
54         List<CldsVfKPIData> cldsKpiList = new ArrayList<>();
55         cldsKpiList.add(cldsVfKpiData);
56         cldsVfData.setCldsKPIList(cldsKpiList);
57
58         List<CldsVfData> cldsVfs = new ArrayList<>();
59         cldsVfs.add(cldsVfData);
60         cldsServiceData.setCldsVfs(cldsVfs);
61
62         CldsDbServiceCache cldsDbServiceCache = new CldsDbServiceCache(cldsServiceData);
63
64         // when
65         ObjectInputStream reader = new ObjectInputStream(cldsDbServiceCache.getCldsDataInstream());
66         CldsServiceData cldsServiceDataResult = (CldsServiceData) reader.readObject();
67
68         // then
69         assertThat(cldsServiceDataResult).isNotNull();
70         assertThat(cldsServiceDataResult.getCldsVfs()).hasSize(1);
71         assertThat(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList()).hasSize(1);
72
73         assertThat(cldsServiceDataResult.getServiceInvariantUUID()).isEqualTo("testInvariantUUID");
74         assertThat(cldsServiceDataResult.getServiceUUID()).isEqualTo("testUUID");
75         assertThat(cldsServiceDataResult.getAgeOfRecord()).isEqualTo(100L);
76     }
77 }