2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.simulator.client.main;
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;
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;
51 @RunWith(MockitoJUnitRunner.class)
53 public class TestClientRunner {
55 JsonRequestHandler jsonRequestHandler;
56 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
59 public void init() throws AppcClientException{
60 System.setOut(new PrintStream(outContent));
61 jsonRequestHandler= Mockito.mock(JsonRequestHandler.class);
65 public void cleanUpStreams() {
69 /* JsinRequestHandler is a constructor
70 * will figure out how to do test without PowerMock later
72 public void testMain() throws java.io.IOException,java.lang.Exception{
73 String []arguments=new String[]{"src/test/resources/data","JSON"};
75 PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler);
76 Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject());
78 ClientRunner.main(arguments);
79 String expectedOutput=outContent.toString();
80 Assert.assertEquals(expectedOutput,outContent.toString());
84 public void testGetPrperties(){
85 String folder="src/test/resources/data";
86 Properties properties=new Properties();
87 properties=getProperties(folder);
88 Assert.assertNotNull(properties);
92 public void testGetJsonFIles() throws FileNotFoundException{
93 String folder="src/test/resources/data";
94 List<File> sources = getJsonFiles(folder);
95 Assert.assertNotNull(sources);
98 private static Properties getProperties(String folder) {
99 Properties prop = new Properties();
101 InputStream conf = null;
103 conf = new FileInputStream(folder + "client-simulator.properties");
104 } catch (FileNotFoundException e) {
110 } catch (IOException e) {
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");
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)));