Replaced all tabs with spaces in java and pom.xml
[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 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.onap.so.TestApplication;
27 import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
28 import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
29 import org.onap.so.db.request.exceptions.NoEntityFoundException;
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.setVnfOperationalEnvId("vnf-oper-env-id-1");
54         status.setRetryCount(0);
55
56         repository.saveAndFlush(status);
57         OperationalEnvServiceModelStatus status2 =
58                 repository.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("oper-env-id-1",
59                         "service-model-ver-id-1", "request-id-1");
60         status2.setRetryCount(1);
61         assertEquals("request-id-1", status2.getRequestId());
62         assertEquals("vnf-oper-env-id-1", status2.getVnfOperationalEnvId());
63
64         repository.saveAndFlush(status2);
65
66         OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus();
67
68         status3.setRequestId("request-id-2");
69         status3.setOperationalEnvId("oper-env-id-1");
70         status3.setServiceModelVersionId("service-model-ver-id-2");
71         status3.setVnfOperationalEnvId("vnf-oper-env-id-2");
72         status3.setRetryCount(2);
73
74         repository.saveAndFlush(status3);
75
76         OperationalEnvServiceModelStatus exampleObj = new OperationalEnvServiceModelStatus();
77         exampleObj.setOperationalEnvId("oper-env-id-1");
78         exampleObj.setServiceModelVersionId("service-model-ver-id-1");
79         ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("requestId");
80         OperationalEnvServiceModelStatus foundStatus = repository.findOne(Example.of(exampleObj, matcher))
81                 .orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation"));
82         if (foundStatus == null)
83             throw new Exception("No status found");
84
85         assertEquals(new Integer(1), foundStatus.getRetryCount());
86     }
87 }