Springboot 2.0 upgrade
[so.git] / mso-api-handlers / mso-requests-db-repositories / src / test / java / org / onap / so / db / request / OperationalEnvServiceModelStatusTest.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
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.so.TestApplication;
28 import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
29 import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
30 import org.onap.so.db.request.exceptions.NoEntityFoundException;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.data.domain.Example;
34 import org.springframework.data.domain.ExampleMatcher;
35 import org.springframework.test.context.ActiveProfiles;
36 import org.springframework.test.context.junit4.SpringRunner;
37
38 @RunWith(SpringRunner.class)
39 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
40 @ActiveProfiles("test")
41 public class OperationalEnvServiceModelStatusTest {
42
43         @Autowired
44         private OperationalEnvServiceModelStatusRepository repository;
45         
46         
47         @Test
48         public void updateWithoutAllKeys() throws Exception {
49                 
50                 OperationalEnvServiceModelStatus status = new OperationalEnvServiceModelStatus();
51                 status.setRequestId("request-id-1");
52                 status.setOperationalEnvId("oper-env-id-1");
53                 status.setServiceModelVersionId("service-model-ver-id-1");
54                 status.setRetryCount(0);
55                 
56                 repository.saveAndFlush(status);
57                 OperationalEnvServiceModelStatus status2 = repository.findOneByOperationalEnvIdAndServiceModelVersionId("oper-env-id-1", "service-model-ver-id-1");
58                 status2.setRetryCount(1);
59                 
60                 repository.saveAndFlush(status2);
61                 
62                 OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus();
63
64                 status3.setRequestId("request-id-2");
65                 status3.setOperationalEnvId("oper-env-id-1");
66                 status3.setServiceModelVersionId("service-model-ver-id-2");
67                 status3.setRetryCount(2);
68                 
69                 repository.saveAndFlush(status3);
70                 
71                 OperationalEnvServiceModelStatus exampleObj = new OperationalEnvServiceModelStatus();
72                 exampleObj.setOperationalEnvId("oper-env-id-1");
73                 exampleObj.setServiceModelVersionId("service-model-ver-id-1");
74                 ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("requestId");
75                 OperationalEnvServiceModelStatus foundStatus = repository.findOne(Example.of(exampleObj,matcher))
76                                 .orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
77                 if(foundStatus== null)
78                         throw new Exception("No status found");
79
80                 assertEquals(new Integer(1), foundStatus.getRetryCount());              
81         }
82 }