2355cb5569235962bddbea0cc26b7eadbf9625ba
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 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
41 import java.io.*;
42 import java.net.URISyntaxException;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.List;
48
49
50 public class TestJsonResponseHandler {
51     String folder="/data/output/error.json";
52     JsonResponseHandler responseHandler=new JsonResponseHandler();
53
54     @Ignore
55     public void testOnResponse() throws URISyntaxException, IOException{
56         responseHandler.onResponse(getNode());
57         List<File> files=getJsonFiles(folder);
58         Assert.assertNotNull(files);
59
60     }
61
62     private String readData(String inputFile) throws URISyntaxException, IOException {
63         File file = new File(this.getClass().getResource(inputFile).toURI());
64
65         byte[] bFile = new byte[(int) file.length()];
66         FileInputStream fileInputStream = new FileInputStream(file);
67         fileInputStream.read(bFile);
68         fileInputStream.close();
69         return new String(bFile);
70     }
71
72     private String getNode() throws java.io.IOException{
73         String jsonSring="{\"status\": {\"code\": \"200\"}}";
74         return  jsonSring;
75 }
76     public  List<File> getJsonFiles(String folder) throws FileNotFoundException {
77         Path dir = Paths.get(folder);
78         FileFilter fileFilter = new WildcardFileFilter("*.error");
79         return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
80     }
81 }