34643a428d78c716c2e633dddffb4b099eeb6bbe
[so.git] / adapters / mso-requests-db-adapter / src / test / java / org / onap / so / adapters / requestdb / rest / RequestProcessingDataRequestDbQueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 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  */
20
21 package org.onap.so.adapters.requestdb.rest;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import javax.transaction.Transactional;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
34 import org.onap.so.db.request.beans.RequestProcessingData;
35 import org.onap.so.db.request.client.RequestsDbClient;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.web.server.LocalServerPort;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.junit4.SpringRunner;
41
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
44 @ActiveProfiles("test")
45 public class RequestProcessingDataRequestDbQueryTest {
46         @Autowired
47         private RequestsDbClient client;
48         
49         @LocalServerPort
50         private int port;
51         
52         @Before
53         public void setPort() {
54                 client.removePortFromEndpoint();
55                 client.setPortToEndpoint(Integer.toString(port));
56         }
57         
58         @Test
59         @Transactional
60         public void RequestProcessingDataBySoRequestIdTest() {
61                 String soRequestId = "00032ab7-na18-42e5-965d-8ea592502018";
62                 String tag = "pincFabricConfigRequest";
63                 RequestProcessingData firstEntry = new RequestProcessingData();
64                 RequestProcessingData secondEntry = new RequestProcessingData();
65                 List<RequestProcessingData> expectedList = new ArrayList<>();
66                 firstEntry.setSoRequestId(soRequestId);
67                 firstEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
68                 firstEntry.setName("configurationId");
69                 firstEntry.setValue("52234bc0-d6a6-41d4-a901-79015e4877e2");
70                 firstEntry.setTag(tag);
71                 secondEntry.setSoRequestId(soRequestId);
72                 secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
73                 secondEntry.setName("requestAction");
74                 secondEntry.setValue("assign");
75                 secondEntry.setTag(tag);
76                 expectedList.add(firstEntry);
77                 expectedList.add(secondEntry);
78
79                 List<RequestProcessingData> dataFound = client.getRequestProcessingDataBySoRequestId(soRequestId);
80                 //bean comparison with shazam fails serialization: Forgot to register a type adapter?
81                 assertEquals(dataFound.get(0).getSoRequestId(), firstEntry.getSoRequestId());
82                 assertEquals(dataFound.get(0).getGroupingId(), firstEntry.getGroupingId());
83                 assertEquals(dataFound.get(0).getName(), firstEntry.getName());
84                 assertEquals(dataFound.get(0).getValue(), firstEntry.getValue());
85                 assertEquals(dataFound.get(0).getTag(), firstEntry.getTag());
86                 assertEquals(dataFound.get(1).getSoRequestId(), secondEntry.getSoRequestId());
87                 assertEquals(dataFound.get(1).getGroupingId(), secondEntry.getGroupingId());
88                 assertEquals(dataFound.get(1).getName(), secondEntry.getName());
89                 assertEquals(dataFound.get(1).getValue(), secondEntry.getValue());
90                 assertEquals(dataFound.get(1).getTag(), secondEntry.getTag());
91         }
92 }