Skip to content
Snippets Groups Projects
Commit 49abd218 authored by Martin Hustoles's avatar Martin Hustoles
Browse files

added sequence diagramm

parent e456b172
No related branches found
No related tags found
No related merge requests found
#https://sequencediagram.org/
title Internetworking WS 23/24
participant CPClient
participant PhyProtocol
participant CPProtocol
participant PhyConfiguration
participant Configuration
participant CPCookieRequestMsg
participant CPMsg
participant PhyMsg
participant CPCookieResponseMsg
#Questions to Schöller
#Timeout Delay? (e.g at receive)
#Classes without Constructor? (e.g at line 60 in CPProtocol)
#
[->CPClient:main
activate CPClient
#Initializing PhyProtocol with everything in it
CPClient->PhyProtocol:<<create>>
activate PhyProtocol
PhyProtocol-->CPClient:
deactivate PhyProtocol
CPClient->CPProtocol:<<create>>
activate CPProtocol
CPProtocol->PhyConfiguration:<<create>>
activate PhyConfiguration
PhyConfiguration->Configuration:<<create>>
activate Configuration
Configuration-->PhyConfiguration:
deactivate Configuration
PhyConfiguration-->CPProtocol:
deactivate PhyConfiguration
CPProtocol-->CPClient:
deactivate CPProtocol
#Sending message from User Input
CPClient->CPProtocol:send()
activate CPProtocol
CPProtocol->CPProtocol:requestCookie()
activate CPProtocol
CPProtocol->CPCookieRequestMsg:create()
activate CPCookieRequestMsg
CPCookieRequestMsg->CPMsg:create()
activate CPMsg
CPMsg-->CPCookieRequestMsg:
deactivate CPMsg
CPCookieRequestMsg-->CPProtocol:
deactivate CPCookieRequestMsg
#calling send() in requestCookie()
CPProtocol->PhyProtocol:send()
activate PhyProtocol
PhyProtocol->PhyMsg:<<create>>
activate PhyMsg
PhyMsg-->PhyProtocol:
deactivate PhyMsg
PhyProtocol-->PhyMsg:create()
activate PhyMsg
PhyMsg-->PhyProtocol:
deactivate PhyMsg
PhyProtocol->PhyProtocol:send()
activate PhyProtocol
space
deactivate PhyProtocol
PhyProtocol-->CPProtocol:
deactivate PhyProtocol
#Receive with Timeout
CPProtocol->PhyProtocol:receive
activate PhyProtocol
PhyProtocol->PhyProtocol:receive
activate PhyProtocol
space
deactivate PhyProtocol
PhyProtocol-->CPProtocol:
deactivate PhyProtocol
#Creates Cookie Response Msg
CPProtocol->CPMsg:
activate CPMsg
CPMsg->CPCookieResponseMsg:<<create>>
activate CPCookieResponseMsg
CPCookieResponseMsg-->CPMsg:
deactivate CPCookieResponseMsg
CPMsg->CPMsg:parse
activate CPMsg
space
deactivate CPMsg
CPMsg-->CPProtocol:
deactivate CPMsg
space
deactivate CPProtocol
CPProtocol-->CPClient:
deactivate CPProtocol
CPClient->CPProtocol:receive
activate CPProtocol
CPProtocol-->CPClient:
deactivate CPProtocol
\ No newline at end of file
sequence.jpg

1.06 MiB

package phy;
import core.Protocol;
import cp.CPProtocol;
import exceptions.CookieRequestException;
import exceptions.IWProtocolException;
import exceptions.IllegalMsgException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
public class CPClientPrintTest {
String serverName = "localhost";
int serverPort = 3027;
@Mock
PhyProtocol phyProtocolMock;
PhyConfiguration phyConfig;
PhyMsg testMsg;
PhyMsg corruptMsg;
CPProtocol cProtocol;
@BeforeEach
void setup() throws UnknownHostException {
try {
phyConfig = new PhyConfiguration(InetAddress.getByName(serverName), serverPort, Protocol.proto_id.CP);
testMsg = new PhyMsg(phyConfig);
corruptMsg = new PhyMsg(phyConfig);
} catch (UnknownHostException e) {
fail();
}
// Set up the object-under-test
cProtocol = new CPProtocol(InetAddress.getByName(serverName), serverPort, phyProtocolMock);
}
@Test
void testCommandResponseOk() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(1)).receive(2000);
}
@Test
void testCommandResponseError() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 error 0 3359664988");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(1)).receive(2000);
}
@Test
void testCommandResponseErrorWithMessage() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 error 16 Out of Resources 996594082");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(1)).receive(2000);
}
@Test
void testCommandResponseOkWithMissingField() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
corruptMsg = (PhyMsg)corruptMsg.parse("phy 7 cp comres 0 4003252835");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(corruptMsg).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(2)).receive(2000);
}
@Test
void testCommandResponseOkWithIllegalField() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
corruptMsg = (PhyMsg)corruptMsg.parse("phy 7 cp comres 1 ok Null 4003252835");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(corruptMsg).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(2)).receive(2000);
}
@Test
void testCommandResponseOkWithIllegalChecksum() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
corruptMsg = (PhyMsg)corruptMsg.parse("phy 7 cp comres 1 ok 0 400325283");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(corruptMsg).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(2)).receive(2000);
}
@Test
void testCommandResponseOkWithTooLongMessage() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
corruptMsg = (PhyMsg)corruptMsg.parse("phy 7 cp comres 1 ok 0 Hello 4003252835");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(corruptMsg).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(2)).receive(2000);
}
@Test
void testCommandResponseOkWithTooShortMessage() throws IWProtocolException, IOException {
// Fill the message object that is going to be returned to the object-under-test
// with the message needed for this test case
testMsg = (PhyMsg)testMsg.parse("phy 7 cp comres 1 ok 0 4003252835");
corruptMsg = (PhyMsg)corruptMsg.parse("phy 7 cp comres 1 ok 10 Hello 4003252835");
// Implement behavior of the mocked object
when(phyProtocolMock.receive(anyInt())).thenReturn(corruptMsg).thenReturn(testMsg);
// Run the test
assertDoesNotThrow(()->cProtocol.receive());
// verify a specified behavior
verify(phyProtocolMock, times(2)).receive(2000);
}
protected long calcCRC(String data) {
// calculate string checksum
byte[] datab = data.getBytes();
Checksum checksum = new CRC32();
checksum.update(datab,0,datab.length);
return checksum.getValue();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment