Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / QueryResourceRecipeTest.java
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 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.db.catalog.beans.ArRecipe;
29 import org.onap.so.db.catalog.beans.NetworkRecipe;
30 import org.onap.so.db.catalog.beans.Recipe;
31 import org.onap.so.db.catalog.beans.ServiceRecipe;
32 import org.onap.so.db.catalog.beans.VnfRecipe;
33 import org.onap.so.jsonpath.JsonPathUtil;
34
35 public class QueryResourceRecipeTest {
36
37     private static final int RECIPE_ID = 123;
38     private static final String RECIPE_ACTION = "actionTest";
39     private static final String RECIPE_URI = "uriTest";
40     private static final int RECIPE_TIMEOUT = 100;
41     private static final String RECIPE_PARAMS_XSD = "paramsXsdTest";
42     private static final String RECIPE_DESCRIPTION = "descrTest";
43
44     private QueryResourceRecipe testedObject;
45
46     @Before
47     public void init() {
48         testedObject = new QueryResourceRecipe(createRecipe());
49     }
50
51     @Test
52     public void convertingToJsonSuccessful() {
53         String jsonResult = testedObject.JSON2(true, true);
54         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.id")).contains(String.valueOf(RECIPE_ID));
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.action")).contains(RECIPE_ACTION);
56         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.orchestrationUri")).contains(RECIPE_URI);
57         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.recipeTimeout"))
58                 .contains(String.valueOf(RECIPE_TIMEOUT));
59         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.paramXSD")).contains(RECIPE_PARAMS_XSD);
60         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(RECIPE_DESCRIPTION);
61     }
62
63     private Recipe createRecipe() {
64         ServiceRecipe recipe = new ServiceRecipe();
65         recipe.setId(RECIPE_ID);
66         recipe.setAction(RECIPE_ACTION);
67         recipe.setOrchestrationUri(RECIPE_URI);
68         recipe.setRecipeTimeout(RECIPE_TIMEOUT);
69         recipe.setParamXsd(RECIPE_PARAMS_XSD);
70         recipe.setDescription(RECIPE_DESCRIPTION);
71         return recipe;
72     }
73
74     @Test
75     public void convertToJson() {
76         Recipe recipe = createRecipe();
77         QueryResourceRecipe queryResourceRecipe = new QueryResourceRecipe(recipe);
78         assertEquals(
79                 "{\"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 =
90                 "{\"orchestrationUri\":\"\",\"action\":\"\",\"description\":\"\",\"id\":\"\",\"recipeTimeout\":\"\",\"paramXSD\":\"\"}";
91         assertEquals(expected, vnfQueryRR.JSON2(false, false));
92         assertEquals(expected, networkQueryRR.JSON2(false, false));
93         assertEquals(expected, arQueryRR.JSON2(false, false));
94     }
95
96 }