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.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
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 OperationStatusTest {
48 private OperationStatusRepository repository;
52 public void timeStampCreated() throws InterruptedException {
54 final String testServiceId = "test-service-id";
55 final String testOperationId = "test-operation-id";
56 final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId);
57 OperationStatus status = new OperationStatus();
59 status.setServiceId(testServiceId);
60 status.setOperationId(testOperationId);
62 status = repository.saveAndFlush(status);
64 OperationStatus found = repository.findOne(id);
66 Date operateAt = found.getOperateAt();
67 assertNotNull(operateAt);
68 assertEquals(testServiceId, found.getServiceId());
69 Date finishedAt = found.getFinishedAt();
70 status.setProgress("test-progress");
71 //timestamps only set to save on 1 second changes
73 repository.saveAndFlush(status);
75 OperationStatus foundUpdate = repository.findOne(id);
77 assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString());
78 assertNotNull(foundUpdate.getFinishedAt());
79 assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString());
80 assertEquals("test-progress", foundUpdate.getProgress());