39cb0da3d431f8a3169421b4e77bbcb48e9c436b
[ccsdk/cds.git] / ms / controllerblueprints / application / src / test / java / org / onap / ccsdk / apps / controllerblueprints / ControllerBluprintsApplicationTest.java
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints;\r
18 \r
19 import static org.assertj.core.api.Assertions.assertThat;\r
20 \r
21 import org.junit.Assert;\r
22 import org.junit.Before;\r
23 import org.junit.Test;\r
24 import org.junit.runner.RunWith;\r
25 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
26 import org.springframework.beans.factory.annotation.Autowired;\r
27 import org.springframework.boot.test.context.SpringBootTest;\r
28 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;\r
29 import org.springframework.boot.test.web.client.TestRestTemplate;\r
30 import org.springframework.http.HttpEntity;\r
31 import org.springframework.http.HttpHeaders;\r
32 import org.springframework.http.HttpMethod;\r
33 import org.springframework.http.HttpStatus;\r
34 import org.springframework.http.MediaType;\r
35 import org.springframework.http.ResponseEntity;\r
36 import org.springframework.test.context.junit4.SpringRunner;\r
37 \r
38 import com.att.eelf.configuration.EELFLogger;\r
39 import com.att.eelf.configuration.EELFManager;\r
40 \r
41 @RunWith(SpringRunner.class)\r
42 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)\r
43 public class ControllerBluprintsApplicationTest {\r
44     private static EELFLogger log = EELFManager.getInstance().getLogger(ControllerBluprintsApplicationTest.class);\r
45 \r
46     @Autowired\r
47     private TestRestTemplate restTemplate;\r
48     private HttpHeaders headers;\r
49     private ResponseEntity<ConfigModel> entity;\r
50 \r
51     @Before\r
52     public void setUp(){\r
53         headers = new HttpHeaders();\r
54         headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);\r
55         entity = this.restTemplate\r
56                 .exchange("/api/v1/config-model/1", HttpMethod.GET, new HttpEntity<>(headers),ConfigModel.class);\r
57         \r
58     }\r
59 \r
60     @Test\r
61     public void testConfigModel() {\r
62         assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);\r
63         Assert.assertNotNull("failed to get response Config model",entity.getBody());\r
64     }\r
65 \r
66     @Test\r
67     public void testConfigModelFailure() {\r
68         assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);\r
69         Assert.assertNotNull("failed to get response Config model",entity.getBody());\r
70     }\r
71 }\r