aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java106
1 files changed, 69 insertions, 37 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java b/vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java
index 0dd6e32a9..922a59200 100644
--- a/vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/model/ModelUtilTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,49 +20,81 @@
package org.onap.vid.model;
-import org.junit.Assert;
-import org.junit.Test;
+import static java.util.Collections.emptyMap;
+import static java.util.function.Function.identity;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anEmptyMap;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.onap.vid.mso.model.ModelInfo;
+import org.testng.annotations.Test;
public class ModelUtilTest {
- private ModelUtil createTestSubject() {
- return new ModelUtil();
- }
+ private final ModelUtil testSubject = new ModelUtil();
+
+ private ModelInfo modelWithCustomizationId(String id) {
+ ModelInfo result = new ModelInfo();
+ result.setModelCustomizationId(id);
+ return result;
+ }
+
+ private ModelInfo modelWithModelVersionId(String id) {
+ ModelInfo result = new ModelInfo();
+ result.setModelVersionId(id);
+ return result;
+ }
-
- @Test
- public void testGetTags() throws Exception {
- String[] namespaces;
- String constantValue = "test";
- String[] result;
+ private ModelInfo modelWithNullValues() {
+ return new ModelInfo();
+ }
- // test 1
- namespaces = null;
- result = ModelUtil.getTags(namespaces, constantValue);
- Assert.assertNull(result);
+ @Test
+ public void getExistingCounterMap_trivialCase() {
+ Map<String, Long> existingCounterMap =
+ testSubject.getExistingCounterMap(
+ ImmutableMap.of(
+ "a", modelWithCustomizationId("model_1"),
+ "b", modelWithCustomizationId("model_1"),
+ "c", modelWithCustomizationId("model_2")
+ ),
+ identity()
+ );
- // test 2
- namespaces = new String[] { "" };
- result = ModelUtil.getTags(namespaces, constantValue);
- Assert.assertArrayEquals(new String[] { constantValue }, result);
- }
+ assertThat(existingCounterMap, jsonEquals(ImmutableMap.of(
+ "model_1", 2,
+ "model_2", 1
+ )));
+ }
-
- @Test
- public void testIsType() throws Exception {
- String type = "a";
- String[] tags;
- boolean result;
+ @Test
+ public void getExistingCounterMap_givenMixOfIdsAndNulls_resultContainsIdsAndOmitsNulls() {
+ Map<String, Long> existingCounterMap =
+ testSubject.getExistingCounterMap(
+ ImmutableMap.of(
+ "a", modelWithCustomizationId("model_1"),
+ "b", modelWithModelVersionId("model_1"),
+ "c", modelWithModelVersionId("model_2"),
+ "d", modelWithNullValues()
+ ),
+ identity()
+ );
- // test 1
- tags = null;
- result = ModelUtil.isType(type, tags);
- Assert.assertEquals(false, result);
+ assertThat(existingCounterMap, jsonEquals(ImmutableMap.of(
+ "model_1", 2,
+ "model_2", 1
+ )));
+ }
- // test 2
- tags = new String[] { "a" };
- result = ModelUtil.isType(type, tags);
- Assert.assertEquals(true, result);
- }
+ @Test
+ public void getExistingCounterMap_handleEmptyCollections() {
+ assertThat(testSubject.getExistingCounterMap(
+ emptyMap(),
+ any -> modelWithCustomizationId("foo")
+ ), is(anEmptyMap()));
+ }
}