Skip to content

Commit

Permalink
added tests for Jcon class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlon Rubio de Carvalho Franco committed Sep 4, 2019
1 parent 6c0163a commit 5ec169f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/com/marlonrcfranco/Jcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public String read(String IP, String filePath, String user, String pass) throws
}
}

public byte[] readBytes(String IP, String filePath, String user, String pass) throws IOException {
return this.jcon.readBytes(IP,filePath,user,pass);
}

public String write(String IP, String filePath, String user, String pass, String content) throws Exception{
String path = "";
try {
Expand All @@ -61,4 +65,8 @@ public String write(String IP, String filePath, String user, String pass, String
}
}

public byte[] writeBytes(String IP, String filePath, String user, String pass, byte[] content) throws IOException {
return this.jcon.writeBytes(IP,filePath,user,pass,content);
}

}
2 changes: 1 addition & 1 deletion src/main/java/tests/JconSMB23Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void write() {
}
}

@Test
@Test
void copyFileTo() {
}

Expand Down
74 changes: 74 additions & 0 deletions src/main/java/tests/JconTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package tests;

import com.marlonrcfranco.IJcon;
import com.marlonrcfranco.Jcon;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

class JconTest {

private Jcon jcon;
private String response;
private String ip;
private String user;
private String password;
private IJcon.types type;
private String basePath;
private String remoteFilePath= "/Teste/arquivo123.xml";
private String remoteImagePath= "/Teste/images.png";
private String remotePDFPath= "/Teste/images.png";
private String localFilePath= "/Teste/images.png";
private String localImagePath= "/Teste/images.png";
private String localPDFPath= "C:\\Users\\marlon.franco\\Documents\\DOUX - Agosto.pdf";

@BeforeEach
void setUp() {
ip = "192.168.35.17";
user = "Adapcon";
password = "1nfr4#2017";
type = IJcon.types.SMB23;
basePath = "Marlon";
this.jcon = new Jcon(type);
this.response="";
}
@Test
void read() {
}

@Test
void write() {
String localBasePath = "C:\\Users\\marlon.franco\\";
try {

/** Test with txt file*/
byte[] TextContent = new Jcon(IJcon.types.FILESYSTEM).readBytes("",localBasePath+"Documents\\teste.txt","","");
this.response = new String(new Jcon(IJcon.types.SMB23).writeBytes(ip,basePath+"/Teste/text.txt",user,password,TextContent));
System.out.println(response);
// read to check if it was written correctly
byte[] TextContent2 = (new Jcon(IJcon.types.SMB23).readBytes(ip,basePath+"/Teste/text.txt",user,password));
assert Arrays.equals(TextContent, TextContent2);

/** Test with PDF file*/
byte[] PDFcontent = new Jcon(IJcon.types.FILESYSTEM).readBytes("",localBasePath+"Documents\\DOUX - Agosto.pdf","","");
this.response = new String(new Jcon(IJcon.types.SMB23).writeBytes(ip,basePath+"/Teste/arquivo.pdf",user,password,PDFcontent));
System.out.println(response);
// read to check if it was written correctly
byte[] PDFcontent2 = (new Jcon(IJcon.types.SMB23).readBytes(ip,basePath+"/Teste/arquivo.pdf",user,password));
assert Arrays.equals(PDFcontent, PDFcontent2);

/** Test with png file*/
byte[] ImageContent = new Jcon(IJcon.types.FILESYSTEM).readBytes("",localBasePath+"Documents\\images.png","","");
this.response = new String(new Jcon(IJcon.types.SMB23).writeBytes(ip,basePath+"/Teste/imageCopy.png",user,password,ImageContent));
System.out.println(response);
// read to check if it was written correctly
byte[] ImageContent2 = (new Jcon(IJcon.types.SMB23).readBytes(ip,basePath+"/Teste/imageCopy.png",user,password));
assert Arrays.equals(ImageContent, ImageContent2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Binary file modified target/classes/com/marlonrcfranco/Jcon.class
Binary file not shown.
Binary file added target/classes/tests/JconTest.class
Binary file not shown.

0 comments on commit 5ec169f

Please sign in to comment.