Merge "Reorder modifiers"
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / openecomp / mso / adapters / catalogdb / catalogrest / QueryServiceCsarTest.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.ToscaCsar;
28 import org.openecomp.mso.jsonpath.JsonPathUtil;
29
30 public class QueryServiceCsarTest {
31
32     private static final String TOSCA_ARTIFACT_UUID = "artUuidTest";
33     private static final String TOSCA_NAME = "toscaNameTest";
34     private static final String TOSCA_VERSION = "v12";
35     private static final String TOSCA_ARTIFACT_CHECKSUM = "tosArtCheck";
36     private static final String TOSCA_URL = "tosUrl";
37     private static final String TOSCA_DESCRIPTION = "toscaDescr";
38
39     private QueryServiceCsar testedObject;
40
41     @Before
42     public void init() {
43         testedObject = new QueryServiceCsar(createToscaCsar());
44     }
45
46     @Test
47     public void convertToJson_successful() {
48         String jsonResult = testedObject.JSON2(true, true);
49         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.artifactUUID")).contains(TOSCA_ARTIFACT_UUID);
50         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.name")).contains(TOSCA_NAME);
51         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.version")).contains(TOSCA_VERSION);
52         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.artifactChecksum"))
53                 .contains(String.valueOf(TOSCA_ARTIFACT_CHECKSUM));
54         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.url")).contains(TOSCA_URL);
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(TOSCA_DESCRIPTION);
56     }
57
58     @Test
59     public void toString_properContent() {
60         assertThat(testedObject.toString()).contains(
61                 "TOSCACSAR: artifactUUID=artUuidTest,name=toscaNameTest,version=v12,description=toscaDescr,artifactChecksum=tosArtCheck,url=tosUrl");
62     }
63
64     private ToscaCsar createToscaCsar() {
65         ToscaCsar toscaCsar = new ToscaCsar();
66         toscaCsar.setArtifactUUID(TOSCA_ARTIFACT_UUID);
67         toscaCsar.setName(TOSCA_NAME);
68         toscaCsar.setVersion(TOSCA_VERSION);
69         toscaCsar.setArtifactChecksum(TOSCA_ARTIFACT_CHECKSUM);
70         toscaCsar.setUrl(TOSCA_URL);
71         toscaCsar.setDescription(TOSCA_DESCRIPTION);
72         return toscaCsar;
73     }
74
75 }