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.openecomp.mso.adapters.catalogdb.catalogrest;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.util.HashMap;
27 import org.junit.Before;
28 import org.junit.Test;
30 public class CatalogQueryTest {
31 private static final String MAP_KEY = "keyTest";
32 private static final String VALUE_MAP = "valueTest";
33 private CatalogQuery testedObject;
37 testedObject = new CatalogQueryForTesting();
41 public void putStringValueToMap() {
42 Map<String, String> valueMap = new HashMap<>();
43 testedObject.put(valueMap, MAP_KEY, VALUE_MAP);
44 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "\"valueTest\"");
48 public void putNullStringValueToMap() {
49 Map<String, String> valueMap = new HashMap<>();
51 testedObject.put(valueMap, MAP_KEY, value);
52 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
56 public void putIntegerValueToMap() {
57 Map<String, String> valueMap = new HashMap<>();
58 testedObject.put(valueMap, MAP_KEY, 1);
59 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "1");
63 public void putNullIntegerValueToMap() {
64 Map<String, String> valueMap = new HashMap<>();
66 testedObject.put(valueMap, MAP_KEY, value);
67 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
71 public void putTrueBooleanValueToMap() {
72 Map<String, String> valueMap = new HashMap<>();
73 testedObject.put(valueMap, MAP_KEY, true);
74 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "true");
78 public void putFalseBooleanValueToMap() {
79 Map<String, String> valueMap = new HashMap<>();
80 testedObject.put(valueMap, MAP_KEY, false);
81 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "false");
85 public void putNullBooleanValueToMap() {
86 Map<String, String> valueMap = new HashMap<>();
88 testedObject.put(valueMap, MAP_KEY, value);
89 assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
93 public void setTemplate_keyFindInMap() {
94 Map<String, String> valueMap = new HashMap<>();
95 valueMap.put(MAP_KEY, VALUE_MAP);
96 String template = "<keyTest>";
97 String result = testedObject.setTemplate(template, valueMap);
98 assertThat(result).isEqualTo(VALUE_MAP);
102 public void setTemplate_keyNotFindInMap() {
103 Map<String, String> valueMap = new HashMap<>();
104 String template = "<keyTest>";
105 String result = testedObject.setTemplate(template, valueMap);
106 assertThat(result).isEqualTo("\"TBD\"");
110 public void setTemplate_templateDoesNotMatch() {
111 Map<String, String> valueMap = new HashMap<>();
112 String template = "key";
113 String result = testedObject.setTemplate(template, valueMap);
114 assertThat(result).isEqualTo("key");
118 public void smartToJson(){
119 String expectedResult = "{\"s\":\"s1\"}";
120 assertThat(testedObject.smartToJSON()).isEqualTo(expectedResult);
124 public void toJsonString_withVersion1() {
125 String expectedResult = "{\"s\":\"s1\"}";
126 assertThat(testedObject.toJsonString("v1",true)).isEqualTo(expectedResult);
130 public void toJsonString_withVersion2() {
131 assertThat(testedObject.toJsonString("v2",true)).isEqualTo("json2");
135 public void toJsonString_withInvalidVersion() {
136 assertThat(testedObject.toJsonString("ver77",true)).isEqualTo("invalid version: ver77");
139 private class CatalogQueryForTesting extends CatalogQuery {
141 private String s = "s1";
143 public String getS() {
148 public String JSON2(boolean isArray, boolean isEmbed) {