Containerization feature of SO
[so.git] / mso-api-handlers / mso-requests-db / src / test / java / org / onap / so / db / request / OperationStatusTest.java
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.assertNotEquals;
25 import static org.junit.Assert.assertNotNull;
26
27 import java.util.Date;
28
29 import javax.transaction.Transactional;
30
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;
41
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
44 @ActiveProfiles("test")
45 public class OperationStatusTest {      
46         
47         @Autowired
48         private OperationStatusRepository repository;
49         
50         @Test
51         @Transactional
52         public void timeStampCreated() throws InterruptedException {
53                 
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();
58                 
59                 status.setServiceId(testServiceId);
60                 status.setOperationId(testOperationId);
61                 
62                 status = repository.saveAndFlush(status);
63                 
64                 OperationStatus found = repository.findOne(id);
65                 
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
72                 Thread.sleep(1000);
73                 repository.saveAndFlush(status);
74                 
75                 OperationStatus foundUpdate = repository.findOne(id);
76
77                 assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString());
78                 assertNotNull(foundUpdate.getFinishedAt());
79                 assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString());
80                 assertEquals("test-progress", foundUpdate.getProgress());
81         }
82 }