Changed to unmaintained
[appc.git] / appc-client / client-simulator / src / test / java / org / onap / appc / simulator / client / main / TestClientRunner.java
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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.simulator.client.main;
25
26 import com.fasterxml.jackson.databind.JsonNode;
27 import org.apache.commons.io.filefilter.WildcardFileFilter;
28 import org.junit.After;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Matchers;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.mockito.internal.stubbing.answers.DoesNothing;
38 import org.mockito.runners.MockitoJUnitRunner;
39 import org.onap.appc.client.lcm.exceptions.AppcClientException;
40 import org.onap.appc.simulator.client.RequestHandler;
41 import org.onap.appc.simulator.client.impl.JsonRequestHandler;
42
43 import java.io.*;
44 import java.nio.file.Path;
45 import java.nio.file.Paths;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.List;
49 import java.util.Properties;
50
51 @RunWith(MockitoJUnitRunner.class)
52
53 public class TestClientRunner {
54
55     JsonRequestHandler jsonRequestHandler;
56     private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
57
58     @Before
59     public void init() throws AppcClientException{
60         System.setOut(new PrintStream(outContent));
61         jsonRequestHandler= Mockito.mock(JsonRequestHandler.class);
62     }
63
64     @After
65     public void cleanUpStreams() {
66         System.setOut(null);
67     }
68
69 /* JsinRequestHandler is a constructor
70  * will figure out how to do test without PowerMock later
71     @Test
72     public void testMain() throws java.io.IOException,java.lang.Exception{
73         String  []arguments=new String[]{"src/test/resources/data","JSON"};
74         
75         PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler);
76         Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject());
77
78         ClientRunner.main(arguments);
79         String expectedOutput=outContent.toString();
80         Assert.assertEquals(expectedOutput,outContent.toString());
81     }
82 */
83     @Test
84     public void testGetPrperties(){
85         String folder="src/test/resources/data";
86         Properties properties=new Properties();
87         properties=getProperties(folder);
88         Assert.assertNotNull(properties);
89     }
90
91     @Test
92     public void testGetJsonFIles() throws FileNotFoundException{
93         String folder="src/test/resources/data";
94         List<File> sources = getJsonFiles(folder);
95         Assert.assertNotNull(sources);
96     }
97
98     private static Properties getProperties(String folder) {
99         Properties prop = new Properties();
100
101         InputStream conf = null;
102         try {
103             conf = new FileInputStream(folder + "client-simulator.properties");
104         } catch (FileNotFoundException e) {
105
106         }
107         if (conf != null) {
108             try {
109                 prop.load(conf);
110             } catch (IOException e) {
111                 e.printStackTrace();
112             }
113         } else {
114             try {
115                 prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
116             } catch (Exception e) {
117                 throw new RuntimeException("### ERROR ### - Could not load properties to test");
118             }
119         }
120         return prop;
121     }
122
123     private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
124         Path dir = Paths.get(folder);
125         FileFilter fileFilter = new WildcardFileFilter("*.json");
126         return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));
127     }
128
129 }