2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.db.request;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import javax.transaction.Transactional;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.onap.so.TestApplication;
30 import org.onap.so.db.request.beans.SiteStatus;
31 import org.onap.so.db.request.data.repository.SiteStatusRepository;
32 import org.onap.so.db.request.exceptions.NoEntityFoundException;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.data.domain.Example;
36 import org.springframework.data.domain.Page;
37 import org.springframework.data.domain.PageRequest;
38 import org.springframework.data.domain.Sort.Direction;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.junit4.SpringRunner;
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
44 @ActiveProfiles("test")
45 public class SiteStatusTest {
48 private SiteStatusRepository repository;
52 public void timeStampCreated() throws InterruptedException, NoEntityFoundException {
54 repository.findById("test name4").orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));
56 assertNotNull(found.getCreated());
57 assertEquals("test name4", found.getSiteName());
61 public void sortByCreated() {
63 final PageRequest page1 = new PageRequest(0, 20, Direction.DESC, "created");
65 SiteStatus example = new SiteStatus();
66 example.setStatus(true);
67 Page<SiteStatus> found = repository.findAll(Example.of(example), page1);
69 assertEquals("test name4", found.getContent().get(0).getSiteName());
74 public void updateStatus() throws NoEntityFoundException {
76 SiteStatus status = repository.findById("test name update")
77 .orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));
78 status.setStatus(false);
80 repository.saveAndFlush(status);
81 status = repository.findById("test name update")
82 .orElseThrow(() -> new NoEntityFoundException("Cannot Find Site"));
83 assertEquals(false, status.getStatus());