Merge "Reorder modifiers"
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / openecomp / mso / 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.openecomp.mso.adapters.catalogdb.catalogrest;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.openecomp.mso.db.catalog.beans.Recipe;
28 import org.openecomp.mso.jsonpath.JsonPathUtil;
29
30 public class QueryResourceRecipeTest {
31
32     private static final int RECIPE_ID = 123;
33     private static final String RECIPE_ACTION = "actionTest";
34     private static final String RECIPE_URI = "uriTest";
35     private static final int RECIPE_TIMEOUT = 100;
36     private static final String RECIPE_PARAMS_XSD = "paramsXsdTest";
37     private static final String RECIPE_DESCRIPTION = "descrTest";
38
39     private QueryResourceRecipe testedObject;
40
41     @Before
42     public void init() {
43         testedObject = new QueryResourceRecipe(createRecipe());
44     }
45
46     @Test
47     public void convertingToJsonSuccessful() {
48         String jsonResult = testedObject.JSON2(true, true);
49         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.id")).contains(String.valueOf(RECIPE_ID));
50         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.action")).contains(RECIPE_ACTION);
51         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.orchestrationUri")).contains(RECIPE_URI);
52         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.recipeTimeout"))
53                 .contains(String.valueOf(RECIPE_TIMEOUT));
54         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.paramXSD")).contains(RECIPE_PARAMS_XSD);
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(RECIPE_DESCRIPTION);
56     }
57
58     @Test
59     public void toString_properContent() {
60         assertThat(testedObject.toString()).contains("RECIPE: actionTest,uri=uriTest");
61     }
62
63     private Recipe createRecipe() {
64         Recipe recipe = new Recipe();
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 }