fe0e1ad5905fb6aec36ed481ba4bee2c336768f1
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.simulator.client.impl;
26
27 import com.fasterxml.jackson.databind.JsonNode;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import org.apache.commons.io.filefilter.WildcardFileFilter;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Ignore;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.mockito.Matchers;
37 import org.mockito.Mockito;
38 import org.mockito.MockitoAnnotations;
39 import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
43
44 import java.io.*;
45 import java.net.URISyntaxException;
46 import java.nio.file.Path;
47 import java.nio.file.Paths;
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.List;
51
52
53 public class TestJsonResponseHandler {
54     String folder="/data/output/error.json";
55     JsonResponseHandler responseHandler=new JsonResponseHandler();
56
57     @Ignore
58     public void testOnResponse() throws URISyntaxException, IOException{
59         responseHandler.onResponse(getNode());
60         List<File> files=getJsonFiles(folder);
61         Assert.assertNotNull(files);
62
63     }
64
65     private String readData(String inputFile) throws URISyntaxException, IOException {
66         File file = new File(this.getClass().getResource(inputFile).toURI());
67
68         byte[] bFile = new byte[(int) file.length()];
69         FileInputStream fileInputStream = new FileInputStream(file);
70         fileInputStream.read(bFile);
71         fileInputStream.close();
72         return new String(bFile);
73     }
74
75     private String getNode() throws java.io.IOException{
76         String jsonSring="{\"status\": {\"code\": \"200\"}}";
77         return  jsonSring;
78 }
79     public  List<File> getJsonFiles(String folder) throws FileNotFoundException {
80         Path dir = Paths.get(folder);
81         FileFilter fileFilter = new WildcardFileFilter("*.error");
82         return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
83     }
84 }