2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.db.request;
23 import static org.junit.Assert.assertEquals;
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;
38 @RunWith(SpringRunner.class)
39 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
40 @ActiveProfiles("test")
41 public class OperationalEnvServiceModelStatusTest {
44 private OperationalEnvServiceModelStatusRepository repository;
48 public void updateWithoutAllKeys() throws Exception {
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);
56 repository.saveAndFlush(status);
57 OperationalEnvServiceModelStatus status2 = repository.findOneByOperationalEnvIdAndServiceModelVersionId("oper-env-id-1", "service-model-ver-id-1");
58 status2.setRetryCount(1);
60 repository.saveAndFlush(status2);
62 OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus();
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);
69 repository.saveAndFlush(status3);
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");
80 assertEquals(new Integer(1), foundStatus.getRetryCount());