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