Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Internetworking_WS23
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Hustoles
Internetworking_WS23
Commits
49abd218
Commit
49abd218
authored
1 year ago
by
Martin Hustoles
Browse files
Options
Downloads
Patches
Plain Diff
added sequence diagramm
parent
e456b172
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CPClient_main.txt
+103
-0
103 additions, 0 deletions
CPClient_main.txt
sequence.jpg
+0
-0
0 additions, 0 deletions
sequence.jpg
src/test/java/phy/CPClientPrintTest.java
+191
-0
191 additions, 0 deletions
src/test/java/phy/CPClientPrintTest.java
with
294 additions
and
0 deletions
CPClient_main.txt
0 → 100644
+
103
−
0
View file @
49abd218
#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
This diff is collapsed.
Click to expand it.
sequence.jpg
0 → 100644
+
0
−
0
View file @
49abd218
1.06 MiB
This diff is collapsed.
Click to expand it.
src/test/java/phy/CPClientPrintTest.java
0 → 100644
+
191
−
0
View file @
49abd218
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
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment