Add missing files

This commit is contained in:
Flare Microsystems
2024-11-11 08:47:15 -08:00
parent b328918684
commit a2a5322835
6 changed files with 314 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.flaremicro.crossjeeves.net;
public class ErrorCodes {
public static final int OK = 0;
public static final int READ_FAILED = 1;
public static final int WRITE_FAILED = 2;
public static final int THREAD_INTERRUPTED = 3;
public static final int SCRIPT_ERROR = 4;
public static final int FILE_DOWNLOAD_FAILURE = 5;
public static final int FILE_UPLOAD_FAILURE = 6;
public static final int INVALID_PACKET_RECIEVED = 7;
}

View File

@@ -0,0 +1,51 @@
package com.flaremicro.crossjeeves.net.packet;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.flaremicro.crossjeeves.net.NetworkHandler;
public class Packet6Disconnect extends Packet{
private int code;
private String reason;
public Packet6Disconnect(){
}
public Packet6Disconnect(int code, String reason){
this.code = code;
this.reason = reason;
}
public void recievePacket(DataInputStream in) throws IOException {
code = in.readInt();
reason = in.readUTF();
}
public void sendPacket(DataOutputStream out) throws IOException {
super.sendPacket(out);
out.writeInt(code);
out.writeUTF(reason);
}
public void processPacket(NetworkHandler networkHandler){
networkHandler.handlePacket(this);
}
public int getCode()
{
return code;
}
public String getReason(){
return this.reason;
}
@Override
public Packet cloneTypeOnly() {
return new Packet6Disconnect();
}
}

View File

@@ -0,0 +1,55 @@
package com.flaremicro.crossjeeves.net.packet;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.flaremicro.crossjeeves.net.NetworkHandler;
public class Packet7LogEntry extends Packet{
public static final byte STD_OUT = 0;
public static final byte STD_ERR = 1;
private byte std;
private String logEntry;
public Packet7LogEntry(){
}
public Packet7LogEntry(byte std, String logEntry){
this.std = std;
this.logEntry = logEntry;
}
public void recievePacket(DataInputStream in) throws IOException {
std = in.readByte();
logEntry = in.readUTF();
}
public void sendPacket(DataOutputStream out) throws IOException {
super.sendPacket(out);
out.writeByte(std);
out.writeUTF(logEntry);
}
public void processPacket(NetworkHandler networkHandler){
networkHandler.handlePacket(this);
}
public byte getStdOutput()
{
return std;
}
public String getLogEntry(){
return this.logEntry;
}
@Override
public Packet cloneTypeOnly() {
return new Packet7LogEntry();
}
}

View File

@@ -0,0 +1,56 @@
package com.flaremicro.crossjeeves.net.packet.test;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import com.flaremicro.crossjeeves.net.NetworkHandler;
import com.flaremicro.crossjeeves.net.packet.Packet;
import com.flaremicro.crossjeeves.net.packet.Packet127KeepAlive;
@RunWith(MockitoJUnitRunner.class)
public class Packet127KeepAliveTest extends PacketTestBase {
@Mock
NetworkHandler handler;
@Test
public void testWrite() throws IOException
{
Packet127KeepAlive packet = new Packet127KeepAlive();
packet.sendPacket(output());
assertEquals(127, input().readByte());
}
@Test
public void testRead() throws IOException
{
Packet127KeepAlive packet = new Packet127KeepAlive();
packet.recievePacket(input());
}
@Test
public void testProcess() throws IOException
{
Packet127KeepAlive packet = new Packet127KeepAlive();
packet.processPacket(handler);
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
}
@Test
public void testTypeCopy()
{
Packet127KeepAlive packet = new Packet127KeepAlive();
Packet clonedPacket = packet.cloneTypeOnly();
assertEquals(packet.getClass(), clonedPacket.getClass());
}
}

View File

@@ -0,0 +1,70 @@
package com.flaremicro.crossjeeves.net.packet.test;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import com.flaremicro.crossjeeves.net.NetworkHandler;
import com.flaremicro.crossjeeves.net.packet.Packet;
import com.flaremicro.crossjeeves.net.packet.Packet6Disconnect;
@RunWith(MockitoJUnitRunner.class)
public class Packet6DisconnectTest extends PacketTestBase {
@Mock
NetworkHandler handler;
private static final byte PACKET_ID = 6;
private static final String REASON = "reason";
private static final int CODE = 1337;
@Test
public void testWrite() throws IOException
{
Packet6Disconnect packet = new Packet6Disconnect(CODE, REASON);
assertEquals(packet.getCode(), CODE);
assertEquals(REASON, packet.getReason());
packet.sendPacket(output());
assertEquals(PACKET_ID, input().readByte());
assertEquals(CODE, input().readInt());
assertEquals(REASON, input().readUTF());
}
@Test
public void testRead() throws IOException
{
Packet6Disconnect packet = new Packet6Disconnect();
output().writeInt(CODE);
output().writeUTF(REASON);
packet.recievePacket(input());
assertEquals(CODE, packet.getCode());
assertEquals(REASON, packet.getReason());
}
@Test
public void testProcess() throws IOException
{
Packet6Disconnect packet = new Packet6Disconnect(CODE, REASON);
packet.processPacket(handler);
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
}
@Test
public void testTypeCopy()
{
Packet6Disconnect packet = new Packet6Disconnect();
Packet clonedPacket = packet.cloneTypeOnly();
assertEquals(packet.getClass(), clonedPacket.getClass());
}
}

View File

@@ -0,0 +1,70 @@
package com.flaremicro.crossjeeves.net.packet.test;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import com.flaremicro.crossjeeves.net.NetworkHandler;
import com.flaremicro.crossjeeves.net.packet.Packet;
import com.flaremicro.crossjeeves.net.packet.Packet7LogEntry;
@RunWith(MockitoJUnitRunner.class)
public class Packet7LogEntryTest extends PacketTestBase {
@Mock
NetworkHandler handler;
private static final byte PACKET_ID = 7;
private static final String LOG_ENTRY = "reason";
private static final byte STD_OUTPUT = Packet7LogEntry.STD_ERR;
@Test
public void testWrite() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry(STD_OUTPUT, LOG_ENTRY);
assertEquals(packet.getStdOutput(), STD_OUTPUT);
assertEquals(LOG_ENTRY, packet.getLogEntry());
packet.sendPacket(output());
assertEquals(PACKET_ID, input().readByte());
assertEquals(STD_OUTPUT, input().readByte());
assertEquals(LOG_ENTRY, input().readUTF());
}
@Test
public void testRead() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry();
output().writeByte(STD_OUTPUT);
output().writeUTF(LOG_ENTRY);
packet.recievePacket(input());
assertEquals(STD_OUTPUT, packet.getStdOutput());
assertEquals(LOG_ENTRY, packet.getLogEntry());
}
@Test
public void testProcess() throws IOException
{
Packet7LogEntry packet = new Packet7LogEntry(STD_OUTPUT, LOG_ENTRY);
packet.processPacket(handler);
Mockito.verify(handler, Mockito.times(1)).handlePacket(packet);
}
@Test
public void testTypeCopy()
{
Packet7LogEntry packet = new Packet7LogEntry();
Packet clonedPacket = packet.cloneTypeOnly();
assertEquals(packet.getClass(), clonedPacket.getClass());
}
}