e403867c4210fee31412b0279297b951d6fcfdaa
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.catalogrest;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.so.db.catalog.beans.ArRecipe;
30 import org.onap.so.db.catalog.beans.NetworkRecipe;
31 import org.onap.so.db.catalog.beans.Recipe;
32 import org.onap.so.db.catalog.beans.ServiceRecipe;
33 import org.onap.so.db.catalog.beans.VnfRecipe;
34 import org.onap.so.jsonpath.JsonPathUtil;
35
36 public class QueryResourceRecipeTest {
37
38     private static final int RECIPE_ID = 123;
39     private static final String RECIPE_ACTION = "actionTest";
40     private static final String RECIPE_URI = "uriTest";
41     private static final int RECIPE_TIMEOUT = 100;
42     private static final String RECIPE_PARAMS_XSD = "paramsXsdTest";
43     private static final String RECIPE_DESCRIPTION = "descrTest";
44
45     private QueryResourceRecipe testedObject;
46
47     @Before
48     public void init() {
49         testedObject = new QueryResourceRecipe(createRecipe());
50     }
51
52     @Test
53     public void convertingToJsonSuccessful() {
54         String jsonResult = testedObject.JSON2(true, true);
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.id")).contains(String.valueOf(RECIPE_ID));
56         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.action")).contains(RECIPE_ACTION);
57         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.orchestrationUri")).contains(RECIPE_URI);
58         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.recipeTimeout"))
59                 .contains(String.valueOf(RECIPE_TIMEOUT));
60         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.paramXSD")).contains(RECIPE_PARAMS_XSD);
61         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(RECIPE_DESCRIPTION);
62     }
63
64     private Recipe createRecipe() {
65         ServiceRecipe recipe = new ServiceRecipe();
66         recipe.setId(RECIPE_ID);
67         recipe.setAction(RECIPE_ACTION);
68         recipe.setOrchestrationUri(RECIPE_URI);
69         recipe.setRecipeTimeout(RECIPE_TIMEOUT);
70         recipe.setParamXsd(RECIPE_PARAMS_XSD);
71         recipe.setDescription(RECIPE_DESCRIPTION);
72         return recipe;
73     }
74
75     @Test
76     public void convertToJson() {
77         Recipe recipe = createRecipe();
78         QueryResourceRecipe queryResourceRecipe = new QueryResourceRecipe(recipe);
79         assertEquals("{\"orchestrationUri\":\"uriTest\",\"action\":\"actionTest\",\"description\":\"descrTest\",\"id\":\"123\",\"recipeTimeout\":\"100\",\"paramXSD\":\"paramsXsdTest\"}",
80                 queryResourceRecipe.JSON2(false,false));
81     }
82
83     @Test
84     public void convertToJsonEmptyRecipe() {
85         QueryResourceRecipe vnfQueryRR = new QueryResourceRecipe(new VnfRecipe());
86         QueryResourceRecipe networkQueryRR = new QueryResourceRecipe(new NetworkRecipe());
87         QueryResourceRecipe arQueryRR = new QueryResourceRecipe(new ArRecipe());
88
89         String expected = "{\"orchestrationUri\":\"\",\"action\":\"\",\"description\":\"\",\"id\":\"\",\"recipeTimeout\":\"\",\"paramXSD\":\"\"}";
90         assertEquals(expected, vnfQueryRR.JSON2(false, false));
91         assertEquals(expected, networkQueryRR.JSON2(false,false));
92         assertEquals(expected, arQueryRR.JSON2(false,false));
93     }
94
95 }