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;
26 import javax.transaction.Transactional;
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.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.data.domain.Example;
37 import org.springframework.data.domain.Page;
38 import org.springframework.data.domain.PageRequest;
39 import org.springframework.data.domain.Sort.Direction;
40 import org.springframework.test.context.ActiveProfiles;
41 import org.springframework.test.context.junit4.SpringRunner;
43 @RunWith(SpringRunner.class)
44 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
45 @ActiveProfiles("test")
46 public class SiteStatusTest {
49 private SiteStatusRepository repository;
53 public void timeStampCreated() throws InterruptedException {
54 SiteStatus found = repository.findOne("test name4");
55 assertNotNull(found.getCreated());
56 assertEquals("test name4", found.getSiteName());
60 public void sortByCreated() {
62 final PageRequest page1 = new PageRequest(
63 0, 20, Direction.DESC, "created"
66 SiteStatus example = new SiteStatus();
67 example.setStatus(true);
68 Page<SiteStatus> found = repository.findAll(Example.of(example), page1);
70 assertEquals("test name4", found.getContent().get(0).getSiteName());
75 public void updateStatus() {
77 SiteStatus status = repository.findOne("test name update");
78 status.setStatus(false);
80 repository.saveAndFlush(status);
82 assertEquals(false, repository.findOne("test name update").getStatus());