2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.openecomp.sdc.be.components.utils;
23 import org.junit.Test;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
29 import static org.assertj.core.api.Assertions.assertThat;
31 public class UtilsTest {
34 public void testThatEmptyListReturns0() {
35 List<String> existingResourceNames = new ArrayList<>();
36 int counter = Utils.getNextCounter(existingResourceNames);
37 assertThat(counter).isZero();
41 public void testListWithValidValue() {
42 List<String> existingResourceNames = Arrays.asList("d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..0");
43 int counter = Utils.getNextCounter(existingResourceNames);
44 assertThat(counter).isEqualTo(1);
48 public void testListWithInvalidSingleValue() {
49 List<String> existingResourceNames = Arrays.asList("d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection");
50 int counter = Utils.getNextCounter(existingResourceNames);
51 assertThat(counter).isEqualTo(1);
55 public void testListWithValidValues() {
56 List<String> existingResourceNames = Arrays.asList("d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..0",
57 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..10",
58 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..15",
59 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..2");
60 int counter = Utils.getNextCounter(existingResourceNames);
61 assertThat(counter).isEqualTo(16);
65 public void testListWithInvalidValue() {
66 List<String> existingResourceNames = Arrays.asList("d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..0",
67 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..10",
68 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection..15",
69 "d7f886ce-7e32-4b1f-bfd8-f664b03fee09.ruti..NetworkCollection");
70 int counter = Utils.getNextCounter(existingResourceNames);
71 assertThat(counter).isEqualTo(16);