Search in sources :

Example 1 with OperationStatusId

use of org.onap.so.db.request.beans.OperationStatusId in project so by onap.

the class OperationStatusTest method timeStampCreated.

@Test
@Transactional
public void timeStampCreated() throws InterruptedException, NoEntityFoundException {
    final String testServiceId = "test-service-id";
    final String testOperationId = "test-operation-id";
    final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId);
    OperationStatus status = new OperationStatus();
    status.setServiceId(testServiceId);
    status.setOperationId(testOperationId);
    status = repository.saveAndFlush(status);
    OperationStatus found = repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
    Date operateAt = found.getOperateAt();
    assertNotNull(operateAt);
    assertEquals(testServiceId, found.getServiceId());
    Date finishedAt = found.getFinishedAt();
    status.setProgress("test-progress");
    // timestamps only set to save on 1 second changes
    Thread.sleep(1000);
    repository.saveAndFlush(status);
    OperationStatus foundUpdate = repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
    assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString());
    assertNotNull(foundUpdate.getFinishedAt());
    assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString());
    assertEquals("test-progress", foundUpdate.getProgress());
}
Also used : OperationStatusId(org.onap.so.db.request.beans.OperationStatusId) OperationStatus(org.onap.so.db.request.beans.OperationStatus) NoEntityFoundException(org.onap.so.db.request.exceptions.NoEntityFoundException) Date(java.util.Date) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(javax.transaction.Transactional)

Aggregations

Date (java.util.Date)1 Transactional (javax.transaction.Transactional)1 Test (org.junit.Test)1 OperationStatus (org.onap.so.db.request.beans.OperationStatus)1 OperationStatusId (org.onap.so.db.request.beans.OperationStatusId)1 NoEntityFoundException (org.onap.so.db.request.exceptions.NoEntityFoundException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1