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