Springboot 2.0 upgrade
[so.git] / mso-api-handlers / mso-requests-db-repositories / src / test / java / org / onap / so / db / request / SiteStatusTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.db.request;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25
26 import javax.transaction.Transactional;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.onap.so.TestApplication;
32 import org.onap.so.db.request.beans.SiteStatus;
33 import org.onap.so.db.request.data.repository.SiteStatusRepository;
34 import org.onap.so.db.request.exceptions.NoEntityFoundException;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.data.domain.Example;
38 import org.springframework.data.domain.Page;
39 import org.springframework.data.domain.PageRequest;
40 import org.springframework.data.domain.Sort.Direction;
41 import org.springframework.test.context.ActiveProfiles;
42 import org.springframework.test.context.junit4.SpringRunner;
43
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
46 @ActiveProfiles("test")
47 public class SiteStatusTest {
48         
49         @Autowired
50         private SiteStatusRepository repository;
51         
52         @Test   
53         @Transactional
54         public void timeStampCreated() throws InterruptedException, NoEntityFoundException {
55                 SiteStatus found = repository.findById("test name4").
56                                 orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));      
57                 
58                 assertNotNull(found.getCreated());
59                 assertEquals("test name4", found.getSiteName());                
60         }
61         
62         @Test
63         public void sortByCreated() {
64                 
65                 final PageRequest page1 = new PageRequest(
66                                   0, 20, Direction.DESC, "created"
67                                 );
68                 
69                 SiteStatus example = new SiteStatus();
70                 example.setStatus(true);
71                 Page<SiteStatus> found = repository.findAll(Example.of(example), page1);
72                 
73                 assertEquals("test name4", found.getContent().get(0).getSiteName());
74                 
75         }
76         
77         @Test
78         public void updateStatus() throws NoEntityFoundException {
79                 
80                 SiteStatus status = repository.findById("test name update").
81                                 orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));      
82                 status.setStatus(false);
83                 
84                 repository.saveAndFlush(status);
85                 status = repository.findById("test name update").
86                                 orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));      
87                 assertEquals(false, status.getStatus());
88                 
89         }
90         
91 }