2 * ============LICENSE_START=======================================================
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
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.onap.appc.client.lcm.exceptions.AppcClientException;
40 import org.onap.appc.simulator.client.RequestHandler;
41 import org.onap.appc.simulator.client.impl.JsonRequestHandler;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.core.classloader.annotations.PrepareForTest;
44 import org.powermock.modules.junit4.PowerMockRunner;
47 import java.nio.file.Path;
48 import java.nio.file.Paths;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.List;
52 import java.util.Properties;
54 @RunWith(PowerMockRunner.class)
55 @PrepareForTest({JsonRequestHandler.class,ClientRunner.class})
57 public class TestClientRunner {
59 JsonRequestHandler jsonRequestHandler;
60 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
63 public void init() throws AppcClientException{
64 System.setOut(new PrintStream(outContent));
65 jsonRequestHandler= Mockito.mock(JsonRequestHandler.class);
70 public void cleanUpStreams() {
75 public void testMain() throws java.io.IOException,java.lang.Exception{
76 String []arguments=new String[]{"src/test/resources/data","JSON"};
77 PowerMockito.whenNew(JsonRequestHandler.class).withArguments(Mockito.anyObject()).thenReturn(jsonRequestHandler);
78 Mockito.doNothing().when(jsonRequestHandler).proceedFile(Matchers.anyObject(), Matchers.anyObject());
80 ClientRunner.main(arguments);
81 String expectedOutput=outContent.toString();
82 Assert.assertEquals(expectedOutput,outContent.toString());
86 public void testGetPrperties(){
87 String folder="src/test/resources/data";
88 Properties properties=new Properties();
89 properties=getProperties(folder);
90 Assert.assertNotNull(properties);
94 public void testGetJsonFIles() throws FileNotFoundException{
95 String folder="src/test/resources/data";
96 List<File> sources = getJsonFiles(folder);
97 Assert.assertNotNull(sources);
100 private static Properties getProperties(String folder) {
101 Properties prop = new Properties();
103 InputStream conf = null;
105 conf = new FileInputStream(folder + "client-simulator.properties");
106 } catch (FileNotFoundException e) {
112 } catch (IOException e) {
117 prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
118 } catch (Exception e) {
119 throw new RuntimeException("### ERROR ### - Could not load properties to test");
125 private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
126 Path dir = Paths.get(folder);
127 FileFilter fileFilter = new WildcardFileFilter("*.json");
128 return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));