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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.simulator.client.main;
27 import com.fasterxml.jackson.databind.JsonNode;
28 import org.apache.commons.io.filefilter.WildcardFileFilter;
29 import org.junit.After;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Matchers;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.mockito.internal.stubbing.answers.DoesNothing;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.appc.client.lcm.exceptions.AppcClientException;
41 import org.onap.appc.simulator.client.RequestHandler;
42 import org.onap.appc.simulator.client.impl.JsonRequestHandler;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.util.ArrayList;
48 import java.util.Arrays;
49 import java.util.List;
50 import java.util.Properties;
52 @RunWith(MockitoJUnitRunner.class)
54 public class TestClientRunner {
56 JsonRequestHandler jsonRequestHandler;
57 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
60 public void init() throws AppcClientException{
61 System.setOut(new PrintStream(outContent));
62 jsonRequestHandler= Mockito.mock(JsonRequestHandler.class);
66 public void cleanUpStreams() {
70 /* JsinRequestHandler is a constructor
71 * will figure out how to do test without PowerMock later
73 public void testMain() throws java.io.IOException,java.lang.Exception{
74 String []arguments=new String[]{"src/test/resources/data","JSON"};
76 PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler);
77 Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject());
79 ClientRunner.main(arguments);
80 String expectedOutput=outContent.toString();
81 Assert.assertEquals(expectedOutput,outContent.toString());
85 public void testGetPrperties(){
86 String folder="src/test/resources/data";
87 Properties properties=new Properties();
88 properties=getProperties(folder);
89 Assert.assertNotNull(properties);
93 public void testGetJsonFIles() throws FileNotFoundException{
94 String folder="src/test/resources/data";
95 List<File> sources = getJsonFiles(folder);
96 Assert.assertNotNull(sources);
99 private static Properties getProperties(String folder) {
100 Properties prop = new Properties();
102 InputStream conf = null;
104 conf = new FileInputStream(folder + "client-simulator.properties");
105 } catch (FileNotFoundException e) {
111 } catch (IOException e) {
116 prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
117 } catch (Exception e) {
118 throw new RuntimeException("### ERROR ### - Could not load properties to test");
124 private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
125 Path dir = Paths.get(folder);
126 FileFilter fileFilter = new WildcardFileFilter("*.json");
127 return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));