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.assertNotEquals;
25 import static org.junit.Assert.assertNotNull;
27 import java.util.Date;
29 import javax.transaction.Transactional;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.onap.so.TestApplication;
34 import org.onap.so.db.request.beans.OperationStatus;
35 import org.onap.so.db.request.beans.OperationStatusId;
36 import org.onap.so.db.request.data.repository.OperationStatusRepository;
37 import org.onap.so.db.request.exceptions.NoEntityFoundException;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.test.context.SpringBootTest;
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 OperationStatusTest {
49 private OperationStatusRepository repository;
53 public void timeStampCreated() throws InterruptedException, NoEntityFoundException {
55 final String testServiceId = "test-service-id";
56 final String testOperationId = "test-operation-id";
57 final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId);
58 OperationStatus status = new OperationStatus();
60 status.setServiceId(testServiceId);
61 status.setOperationId(testOperationId);
63 status = repository.saveAndFlush(status);
65 OperationStatus found = repository.findById(id).
66 orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
68 Date operateAt = found.getOperateAt();
69 assertNotNull(operateAt);
70 assertEquals(testServiceId, found.getServiceId());
71 Date finishedAt = found.getFinishedAt();
72 status.setProgress("test-progress");
73 //timestamps only set to save on 1 second changes
75 repository.saveAndFlush(status);
77 OperationStatus foundUpdate = repository.findById(id).
78 orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
80 assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString());
81 assertNotNull(foundUpdate.getFinishedAt());
82 assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString());
83 assertEquals("test-progress", foundUpdate.getProgress());