2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.ccsdk.apps.ms.neng.core.seq;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.mock;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.runners.MockitoJUnitRunner;
32 import org.onap.ccsdk.apps.ms.neng.core.policy.PolicySequence;
33 import org.onap.ccsdk.apps.ms.neng.persistence.entity.ServiceParameter;
34 import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
35 import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
38 @RunWith(MockitoJUnitRunner.class)
39 public class SequenceGeneratorTest {
41 private GeneratedNameRespository genNameRepo = mock(GeneratedNameRespository.class);
43 private ServiceParameterRepository servParamRepo = mock(ServiceParameterRepository.class);
45 private PolicySequence params = mock(PolicySequence.class);
47 private ServiceParameter sp = mock(ServiceParameter.class);
52 public void testGenerate() throws Exception {
53 assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
55 Mockito.lenient().when(params.getLastReleaseSeqNumTried()).thenReturn(null);
56 Mockito.lenient().when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("4");
58 assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
60 Mockito.lenient().when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("2");
61 Mockito.lenient().when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn(null);
62 Mockito.lenient().when(servParamRepo.findByName("initial_increment")).thenReturn(sp);
63 Mockito.lenient().when(sp.getValue()).thenReturn("1");
65 assertEquals(0, sg.generate("zSSRX1234", null, params, 1L, 2));
67 Mockito.lenient().when(genNameRepo.findNextReleasedSeq(0L, "zSSRX1234", null)).thenReturn(null);
68 assertEquals(0, sg.generate("zSSRX1234", null, params, null, 1));
71 @Test(expected = Exception.class)
72 public void exceltionTest() throws Exception {
73 Mockito.lenient().when(genNameRepo.findNextReleasedSeq(1L, "zSSRX1234", null)).thenReturn(null);
74 Mockito.lenient().when(params.getLastReleaseSeqNumTried()).thenReturn(1L);
75 sg.generate("zSSRX1234", null, params, null, 1);
79 public void testAlreadyUsedSequesnce() throws Exception {
80 Mockito.lenient().when(genNameRepo.findMaxByPrefixAndSuffix("zSSRX1234", null)).thenReturn("1");
81 Mockito.lenient().when(sp.getValue()).thenReturn("4");
82 Mockito.lenient().when(params.getIncrement()).thenReturn(2L);
83 assertEquals(0L, sg.generate("zSSRX1234", null, params, 2L, 0));