Added UniversalVesAdapter TestCases in the Mapper
[dcaegen2/services/mapper.git] / UniversalVesAdapter / src / test / java / org / onap / universalvesadapter / service / DiskRepoConfigFileServiceTest.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DCAE
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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 package org.onap.universalvesadapter.service;
21
22 import static org.junit.Assert.assertEquals;
23 import java.net.URI;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.onap.universalvesadapter.Application;
32 import org.onap.universalvesadapter.exception.ConfigFileReadException;
33 import org.onap.universalvesadapter.service.DiskRepoConfigFileService;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.test.context.junit4.SpringRunner;
41 import org.springframework.web.client.RestTemplate;
42
43 @RunWith(SpringRunner.class)
44 @SpringBootTest(classes = Application.class)
45 public class DiskRepoConfigFileServiceTest {
46
47     @Mock
48     RestTemplate restTemplate;
49     
50     @InjectMocks
51     @Autowired
52     DiskRepoConfigFileService diskRepoConfigFileService;
53     
54     private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass());
55
56     @Before
57     public void init() {
58         MockitoAnnotations.initMocks(this);
59     }   
60     
61     
62     @Test
63     public void testReadConfigFile() {
64         
65         String result = "test file";
66
67         ResponseEntity<String> fileDataEntity = new ResponseEntity<String>(result, HttpStatus.OK);
68         
69         Mockito.when(restTemplate.getForEntity(Mockito.any(URI.class), Mockito.any(Class.class))).thenReturn(fileDataEntity);
70         
71         try {
72             String readConfigFile = diskRepoConfigFileService.readConfigFile("testCase.xml");
73             assertEquals(result, readConfigFile);
74         } catch (ConfigFileReadException exception) {
75             eLOGGER.error("Error occurred : ", exception);
76         }
77         
78     }
79
80 }