// Path: src/main/java/client/LocalIPMIClient.java
// public class LocalIPMIClient extends IPMIClient {
// 
// 	public LocalIPMIClient(Platform platform) {
// 		super("127.0.0.1","", "", null, platform);
// 	}
// 
// }
// 
// Path: src/main/java/command/Command.java
// public class Command {
// 	public OutputResult exeCmd(String commandStr) {
// 		BufferedReader br = null;
// 		OutputResult out = new OutputResult();
// 		try {
// 			Process p = Runtime.getRuntime().exec(commandStr);
// 			br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 			String line;
// 			while ((line = br.readLine()) != null) {
// 				out.add(line.trim());
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		} finally{
// 			if (br != null)
// 			{
// 				try {
// 					br.close();
// 				} catch (Exception e) {
// 					e.printStackTrace();
// 				}
// 			}
// 		}
// 		return out;
// 	}
// 	public OutputResult exeCmdOnLinux(String cmd){
// 		String[] command = {"/bin/sh", "-c", cmd};
// 		OutputResult out = new OutputResult();
// 		BufferedReader br = null;
// 		try {
// 			Process p = Runtime.getRuntime().exec(command);
// 			br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 			String line;
// 			while ((line = br.readLine()) != null) {
// 				out.add(line.trim());
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		} finally{
// 			if (br != null)
// 			{
// 				try {
// 					br.close();
// 				} catch (Exception e) {
// 					e.printStackTrace();
// 				}
// 			}
// 		}
// 		return out;
// 	}
// 
// 	public static void main(String[] args) throws IOException {
// 		Runtime runtime = Runtime.getRuntime();
// 		Process p = runtime.exec("ipmiutil-2.9.6-win64/ipmiutil fru -N 10.4.33.146 -U Administrator -P rdis2fun! -J 3");
// 		BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 		String line = null;
// 		StringBuilder sb = new StringBuilder();
// 		while ((line = br.readLine()) != null) {
// 			sb.append(line + "\n");
// 		}
// 		System.out.println(sb.toString());
// 	}
// }
// 
// Path: src/main/java/model/ComponentFru.java
// public class ComponentFru extends Fru {
// 
//     public ComponentFru(String name) {
//         super(name);
//     }
// }
// 
// Path: src/main/java/param/Platform.java
// public enum Platform {
//     TIGPT1U(""),
//     NSC2U(""),
//     Ubuntu("/bin/sh -c ipmiutil"),
//     Linux("/bin/sh -c ipmiutil"),
//     Win32("cmd.exe /C ipmiutil-win32/ipmiutil"),
//     Win64("cmd.exe /C ipmiutil-win64/ipmiutil");
// 
//     private String IPMI_META_COMMAND;
//     private Platform(String command){
//         IPMI_META_COMMAND = command;
//     }
// 
//     public String getIPMI_META_COMMAND() {
//         return IPMI_META_COMMAND;
//     }
// }
// 
// Path: src/main/java/respond/FruRespond.java
// public class FruRespond implements IPMIRespond{
//     private List<Fru> frus;
//     private boolean isSuccess;
//     public synchronized void addFru(Fru fru){
//         if(frus == null){
//             frus = new ArrayList<Fru>();
//         }
//         frus.add(fru);
//     }
//     @Override
//     public boolean hasRespond() {
//         return isSuccess;
//     }
// 
//     public void setSuccess(boolean isSuccess) {
//         this.isSuccess = isSuccess;
//     }
// 
//     public <T> List<T> getFrus(Class clazz){
//         if(frus == null){
//             return Collections.emptyList();
//         }
//         List<T> rs = new ArrayList<T>(frus.size());
//         for(Fru fru : frus){
//             if(fru.getClass().equals(clazz)){
//                 rs.add((T)fru);
//             }
//         }
//         return rs;
//     }
// }
// 
// Path: src/test/util/ReadFileAsInput.java
// public class ReadFileAsInput {
//     public static OutputResult readFile(String path) throws IOException {
//         OutputResult or = new OutputResult();
//         BufferedReader br = new BufferedReader((new InputStreamReader(ReadFileAsInput.class.getResourceAsStream(path))));
//         String line;
//         while ((line = br.readLine()) != null) {
//             or.add(line);
//         }
//         return or;
//     }
// }


import client.LocalIPMIClient;
import command.Command;
import model.ComponentFru;
import org.junit.Assert;
import org.junit.Test;
import param.Platform;
import respond.FruRespond;
import java.io.IOException;
import static org.mockito.Matchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static util.ReadFileAsInput.*;
/*
 * testFru.java
 * Date: 7/14/2015
 * Time: 5:24 PM
 * 
 * Copyright 2015 luoyuan.
 * ALL RIGHTS RESERVED.
*/

package request;




public class TestFru {

    @Test
    public void testFruRequest() throws IOException {
        Command command = mock(Command.class);
        when(command.exeCmd(contains("ipmiutil fru"))).thenReturn(readFile("../data/fru-output"));
        LocalIPMIClient client = new LocalIPMIClient(Platform.Win64);
        FruRequest request = new FruRequest();
        request.setCommand(command);
        FruRespond respond = request.sendTo(client);
// Path: src/main/java/client/LocalIPMIClient.java
// public class LocalIPMIClient extends IPMIClient {
// 
// 	public LocalIPMIClient(Platform platform) {
// 		super("127.0.0.1","", "", null, platform);
// 	}
// 
// }
// 
// Path: src/main/java/command/Command.java
// public class Command {
// 	public OutputResult exeCmd(String commandStr) {
// 		BufferedReader br = null;
// 		OutputResult out = new OutputResult();
// 		try {
// 			Process p = Runtime.getRuntime().exec(commandStr);
// 			br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 			String line;
// 			while ((line = br.readLine()) != null) {
// 				out.add(line.trim());
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		} finally{
// 			if (br != null)
// 			{
// 				try {
// 					br.close();
// 				} catch (Exception e) {
// 					e.printStackTrace();
// 				}
// 			}
// 		}
// 		return out;
// 	}
// 	public OutputResult exeCmdOnLinux(String cmd){
// 		String[] command = {"/bin/sh", "-c", cmd};
// 		OutputResult out = new OutputResult();
// 		BufferedReader br = null;
// 		try {
// 			Process p = Runtime.getRuntime().exec(command);
// 			br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 			String line;
// 			while ((line = br.readLine()) != null) {
// 				out.add(line.trim());
// 			}
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		} finally{
// 			if (br != null)
// 			{
// 				try {
// 					br.close();
// 				} catch (Exception e) {
// 					e.printStackTrace();
// 				}
// 			}
// 		}
// 		return out;
// 	}
// 
// 	public static void main(String[] args) throws IOException {
// 		Runtime runtime = Runtime.getRuntime();
// 		Process p = runtime.exec("ipmiutil-2.9.6-win64/ipmiutil fru -N 10.4.33.146 -U Administrator -P rdis2fun! -J 3");
// 		BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
// 		String line = null;
// 		StringBuilder sb = new StringBuilder();
// 		while ((line = br.readLine()) != null) {
// 			sb.append(line + "\n");
// 		}
// 		System.out.println(sb.toString());
// 	}
// }
// 
// Path: src/main/java/model/ComponentFru.java
// public class ComponentFru extends Fru {
// 
//     public ComponentFru(String name) {
//         super(name);
//     }
// }
// 
// Path: src/main/java/param/Platform.java
// public enum Platform {
//     TIGPT1U(""),
//     NSC2U(""),
//     Ubuntu("/bin/sh -c ipmiutil"),
//     Linux("/bin/sh -c ipmiutil"),
//     Win32("cmd.exe /C ipmiutil-win32/ipmiutil"),
//     Win64("cmd.exe /C ipmiutil-win64/ipmiutil");
// 
//     private String IPMI_META_COMMAND;
//     private Platform(String command){
//         IPMI_META_COMMAND = command;
//     }
// 
//     public String getIPMI_META_COMMAND() {
//         return IPMI_META_COMMAND;
//     }
// }
// 
// Path: src/main/java/respond/FruRespond.java
// public class FruRespond implements IPMIRespond{
//     private List<Fru> frus;
//     private boolean isSuccess;
//     public synchronized void addFru(Fru fru){
//         if(frus == null){
//             frus = new ArrayList<Fru>();
//         }
//         frus.add(fru);
//     }
//     @Override
//     public boolean hasRespond() {
//         return isSuccess;
//     }
// 
//     public void setSuccess(boolean isSuccess) {
//         this.isSuccess = isSuccess;
//     }
// 
//     public <T> List<T> getFrus(Class clazz){
//         if(frus == null){
//             return Collections.emptyList();
//         }
//         List<T> rs = new ArrayList<T>(frus.size());
//         for(Fru fru : frus){
//             if(fru.getClass().equals(clazz)){
//                 rs.add((T)fru);
//             }
//         }
//         return rs;
//     }
// }
// 
// Path: src/test/util/ReadFileAsInput.java
// public class ReadFileAsInput {
//     public static OutputResult readFile(String path) throws IOException {
//         OutputResult or = new OutputResult();
//         BufferedReader br = new BufferedReader((new InputStreamReader(ReadFileAsInput.class.getResourceAsStream(path))));
//         String line;
//         while ((line = br.readLine()) != null) {
//             or.add(line);
//         }
//         return or;
//     }
// }


// Path: src/test/request/testFru.java
import client.LocalIPMIClient;
import command.Command;
import model.ComponentFru;
import org.junit.Assert;
import org.junit.Test;
import param.Platform;
import respond.FruRespond;
import java.io.IOException;
import static org.mockito.Matchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static util.ReadFileAsInput.*;

/*
 * testFru.java
 * Date: 7/14/2015
 * Time: 5:24 PM
 * 
 * Copyright 2015 luoyuan.
 * ALL RIGHTS RESERVED.
*/

package request;




public class TestFru {

    @Test
    public void testFruRequest() throws IOException {
        Command command = mock(Command.class);
        when(command.exeCmd(contains("ipmiutil fru"))).thenReturn(readFile("../data/fru-output"));
        LocalIPMIClient client = new LocalIPMIClient(Platform.Win64);
        FruRequest request = new FruRequest();
        request.setCommand(command);
        FruRespond respond = request.sendTo(client);
        Assert.assertTrue(respond.hasRespond());