diff --git a/README.md b/README.md index eb0c440..08f45bb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# Download the "JAR.FILE.IS.IN.HERE" zip file from final release, extract and run the .jar file +there are a few example databases in that zip as well, however you can delete the .json files in case you do not need any example data + + + + + + # Remote-Container-Management Use Eclipse to edit the repository by either pulling, or committing and pushing. @@ -9,8 +17,3 @@ Thereafter, when starting a work session, be sure to pull in order to get the up The convetion for writing packages: myPackage; classes: Class; methods: method. - - - - - diff --git a/System/.classpath b/System/.classpath index f4bf436..c3f70d9 100644 --- a/System/.classpath +++ b/System/.classpath @@ -18,11 +18,7 @@ - - - - - + diff --git a/System/.settings/org.eclipse.jdt.core.prefs b/System/.settings/org.eclipse.jdt.core.prefs index 741b8a7..5208f74 100644 --- a/System/.settings/org.eclipse.jdt.core.prefs +++ b/System/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -13,4 +13,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/System/UMLdiagram.png b/System/UMLdiagram.png new file mode 100644 index 0000000..8931be8 Binary files /dev/null and b/System/UMLdiagram.png differ diff --git a/System/UMLdiagram.ucls b/System/UMLdiagram.ucls new file mode 100644 index 0000000..3d85342 --- /dev/null +++ b/System/UMLdiagram.ucls @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/System/cargo_blue.gif b/System/cargo_blue.gif new file mode 100644 index 0000000..9e535f0 Binary files /dev/null and b/System/cargo_blue.gif differ diff --git a/System/client_database.json b/System/client_database.json new file mode 100644 index 0000000..fcab2f2 --- /dev/null +++ b/System/client_database.json @@ -0,0 +1,81 @@ +{ + "clients" : [ { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 1, + "fistName" : "Alan", + "lastName" : "Mansour", + "birthDate" : "21/04/2021", + "email" : "Alan.Mansour@mail.com", + "password" : "0000", + "phoneNumber" : "0000000001", + "friends" : [ ] + }, { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 2, + "fistName" : "Javier", + "lastName" : "Almendra", + "birthDate" : "21/04/2021", + "email" : "Javier.Almendra@mail.com", + "password" : "0000", + "phoneNumber" : "0000000002", + "friends" : [ ] + }, { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 3, + "fistName" : "Kristyn", + "lastName" : "Korboe", + "birthDate" : "21/04/2021", + "email" : "Kristyn.Korboe@mail.com", + "password" : "0000", + "phoneNumber" : "0000000003", + "friends" : [ ] + }, { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 4, + "fistName" : "Ousama", + "lastName" : "Mhadden", + "birthDate" : "21/04/2021", + "email" : "Ousama.Mhadden@mail.com", + "password" : "0000", + "phoneNumber" : "0000000004", + "friends" : [ ] + }, { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 5, + "fistName" : "Parsa", + "lastName" : "Mehrizi", + "birthDate" : "21/04/2021", + "email" : "Parsa.Mehrizi@mail.com", + "password" : "0000", + "phoneNumber" : "0000000005", + "friends" : [ ] + }, { + "myContainers" : [ ], + "myJourneys" : { + "journeys" : { } + }, + "id" : 6, + "fistName" : "Sarthak", + "lastName" : "Trehan", + "birthDate" : "21/04/2021", + "email" : "Sarthak.Trehan@mail.com", + "password" : "0000", + "phoneNumber" : "0000000006", + "friends" : [ ] + } ] +} \ No newline at end of file diff --git a/System/container_database.json b/System/container_database.json new file mode 100644 index 0000000..fa1a8bf --- /dev/null +++ b/System/container_database.json @@ -0,0 +1,523 @@ +{ + "containers" : [ { + "containerID" : 1, + "owner" : 1, + "position" : "Copenhagen", + "contentType" : "Fish", + "company" : "Captain Fish", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 2, + "owner" : 1, + "position" : "Copenhagen", + "contentType" : "Fish", + "company" : "Captain Fish", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 3, + "owner" : 4, + "position" : "Copenhagen", + "contentType" : "Banana", + "company" : "Captain Banana", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 4, + "owner" : 4, + "position" : "Copenhagen", + "contentType" : "Banana", + "company" : "Captain Banana", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 5, + "owner" : 4, + "position" : "Copenhagen", + "contentType" : "Banana", + "company" : "Captain Banana", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 6, + "owner" : 4, + "position" : "Copenhagen", + "contentType" : "Banana", + "company" : "Captain Banana", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 7, + "owner" : 4, + "position" : "Copenhagen", + "contentType" : "Banana", + "company" : "Captain Banana", + "availability" : false, + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 8, + "owner" : 0, + "position" : "Copenhagen", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 9, + "owner" : 0, + "position" : "Copenhagen", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 10, + "owner" : 0, + "position" : "Copenhagen", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 11, + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 12, + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 13, + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 14, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 15, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 16, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 17, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 18, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 19, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 20, + "owner" : 0, + "position" : "Oslo", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 21, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 22, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 23, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 24, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 25, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 26, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 27, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 28, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 29, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 30, + "owner" : 0, + "position" : "Gothenburg", + "contentType" : null, + "company" : null, + "availability" : true, + "currentJourney" : null, + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 31, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 32, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 33, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 34, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 35, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 36, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 37, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 38, + "owner" : 3, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 39, + "owner" : 3, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 40, + "owner" : 6, + "position" : "Amsterdam", + "contentType" : "Tobacco", + "company" : "Captain Tobacco", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + } ] +} \ No newline at end of file diff --git a/System/journey_database.json b/System/journey_database.json index 00bbf28..4755e30 100644 --- a/System/journey_database.json +++ b/System/journey_database.json @@ -1,126 +1,321 @@ { "journeys" : { - "\"{ID : CO23143, Origin : Copenhagen, Destination : Oslo, Departure : null, Arrival : null}\"" : [ { + "\"{ID : CO23143, Origin : Copenhagen, Destination : Oslo, Departure : 21/04/2021, Arrival : 22/04/2021}\"" : [ { "containerID" : 1, - "owner" : 100, + "owner" : 1, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Fish", + "company" : "Captain Fish", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 2, - "owner" : 100, + "owner" : 1, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Fish", + "company" : "Captain Fish", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 3, - "owner" : 100, + "owner" : 4, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Banana", + "company" : "Captain Banana", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 4, - "owner" : 100, + "owner" : 4, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Banana", + "company" : "Captain Banana", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 5, - "owner" : 100, + "owner" : 4, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Banana", + "company" : "Captain Banana", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 6, - "owner" : 100, + "owner" : 4, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Banana", + "company" : "Captain Banana", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { "containerID" : 7, - "owner" : 100, + "owner" : 4, "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "contentType" : "Banana", + "company" : "Captain Banana", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "CO23143", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + } ], + "\"{ID : AC21003, Origin : Amsterdam, Destination : Copenhagen, Departure : 12/06/2021, Arrival : 15/06/2021}\"" : [ { + "containerID" : 31, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { - "containerID" : 8, - "owner" : 100, - "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "containerID" : 32, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { - "containerID" : 9, - "owner" : 100, - "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "containerID" : 33, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { - "containerID" : 10, - "owner" : 100, - "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "containerID" : 34, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 35, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 36, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 37, + "owner" : 2, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Flower", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 38, + "owner" : 3, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 39, + "owner" : 3, + "position" : "Amsterdam", + "contentType" : "Flowers", + "company" : "Captain Textile", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] }, { + "containerID" : 40, + "owner" : 6, + "position" : "Amsterdam", + "contentType" : "Tobacco", + "company" : "Captain Tobacco", + "availability" : false, + "currentJourney" : "AC21003", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + } ], + "\"{ID : CO22211, Origin : Copenhagen, Destination : Oslo, Departure : 30/04/2021, Arrival : 31/04/2021}\"" : [ ], + "\"{ID : OC32413, Origin : Oslo, Destination : Copenhagen, Departure : 29/05/2021, Arrival : 30/05/2021}\"" : [ { "containerID" : 11, - "owner" : 100, - "position" : "Copenhagen", - "contentType" : "fish", - "company" : "Banana Company", + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 12, + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 13, + "owner" : 3, + "position" : "Oslo", + "contentType" : "Textile", + "company" : "Captain Textile", + "availability" : false, + "currentJourney" : "OC32413", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + } ], + "\"{ID : GA12147, Origin : Gothenburg, Destination : Amsterdam, Departure : 17/05/2021, Arrival : 19/05/2021}\"" : [ { + "containerID" : 21, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 22, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 23, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", + "availability" : false, + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] + }, { + "containerID" : 24, + "owner" : 5, + "position" : "Gothenburg", + "contentType" : "Plastic", + "company" : "Captain Plastic", "availability" : false, - "temperature" : 20, - "humidity" : 21, - "pressure" : 22, - "history" : [ [ [ ] ], [ [ 20, 20, 20 ] ], [ [ 21, 21, 21 ] ], [ [ 22, 22, 22 ] ], [ [ "Copenhagen", "Copenhagen", "Copenhagen" ] ] ] + "currentJourney" : "GA12147", + "temperature" : 0, + "humidity" : 0, + "pressure" : 0, + "date" : null, + "history" : [ [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ], [ [ ] ] ] } ] } } \ No newline at end of file diff --git a/System/pom.xml b/System/pom.xml index 3d9bf9a..bc3b6c7 100644 --- a/System/pom.xml +++ b/System/pom.xml @@ -4,9 +4,27 @@ System 0.0.1-SNAPSHOT + + + + maven-assembly-plugin + + + + controller.ApplicationController + + + + jar-with-dependencies + + + + + + - 11 - 11 + 1.8 + 1.8 @@ -47,6 +65,12 @@ 2.12.2 + + org.apache.commons + commons-text + 1.1 + + \ No newline at end of file diff --git a/System/src/main/java/JsonDatabase.java b/System/src/main/java/JsonDatabase.java deleted file mode 100644 index 934bd3b..0000000 --- a/System/src/main/java/JsonDatabase.java +++ /dev/null @@ -1,101 +0,0 @@ -import java.io.File; -import java.io.FileReader; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; - -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import clientsManagement.Client; -import journeysManagement.Container; -import journeysManagement.ContainerDatabase; -import journeysManagement.Journey; -import journeysManagement.JourneyDatabase; - -public class JsonDatabase { - - public static void main(String[] args) throws Exception { - - JourneyDatabase journeys = new JourneyDatabase(); - ContainerDatabase containers = new ContainerDatabase(); - ObjectMapper mapper = new ObjectMapper(); - - JSONObject sampleObject = new JSONObject(); - Files.write(Paths.get("example.json"), sampleObject.toJSONString().getBytes()); - - Journey journey1 = new Journey(); - journey1.setJourneyID("CO23092"); - journey1.setOrigin("Copenhagen"); - journey1.setDestination("Oslo"); - journeys.create(journey1); - create("example.json", journey1, journeys); - - Journey journey2 = new Journey(); - journey2.setJourneyID("CO23392"); - journey2.setOrigin("Amsterdam"); - journey2.setDestination("Copenhagen"); - journeys.create(journey2); - create("example.json", journey2, journeys); - - Journey journey3 = new Journey(); - journey3.setJourneyID("CO23192"); - journey3.setOrigin("Amsterdam"); - journey3.setDestination("Copenhagen"); - journeys.create(journey3); - create("example.json", journey3, journeys); - -// for (int i = 1; i <= 5; i++) { -// containers.getContainers().add(new Container()); -// containers.getContainers().get(i - 1).setContainerID(i); -// containers.getContainers().get(i - 1).setPosition("Copenhagen"); -// containers.getContainers().get(i - 1).setAvailability(true); -// } -// -// Client client = new Client(); -// client.registerContainers("Copenhagen", "Fish", "Maersk", 2, containers); -// journeys.registerTo("CO23092", "Copenhagen", "Oslo", client.getMyContainers()); -// String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(journeys); -// journeys.push(); -// //Files.write(Paths.get("example.json"), jsonResult.getBytes()); -// -// journeys.pull(); -// //journeys = mapper.readValue(new File("example.json"), JourneyDatabase.class); -// -// for(Journey key : journeys.getJourneys().keySet()) { -// -// for (Container container : journeys.getJourneys().get(key)) { -// -// System.out.println(container.getPosition()); -// -// } -// -// } -// - - - //Files.write(Paths.get("example.json"), jsonObject.toJSONString().getBytes()); - - } - - public static void create(String filename, Journey journey, JourneyDatabase journeys) throws Exception { - ObjectMapper mapper = new ObjectMapper(); - - ArrayList containerList = new ArrayList(); - journeys.getJourneys().put(journey, containerList); - String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(journeys); - Files.write(Paths.get(filename), jsonResult.getBytes()); - } - - // replaceAll("\\\\","") - public static Object readJsonSimpleDemo(String filename) throws Exception { - FileReader reader = new FileReader(filename); - JSONParser jsonParser = new JSONParser(); - return jsonParser.parse(reader); - } - - -} diff --git a/System/src/main/java/Testing.java b/System/src/main/java/Testing.java deleted file mode 100644 index fa3b179..0000000 --- a/System/src/main/java/Testing.java +++ /dev/null @@ -1,75 +0,0 @@ -//import java.time.Instant; - -import clientsManagement.Client; -import journeysManagement.Container; -import journeysManagement.ContainerDatabase; -import journeysManagement.Journey; -import journeysManagement.JourneyDatabase; - -public class Testing { - - public static void main(String[] args) { - - JourneyDatabase journeys = new JourneyDatabase(); - - try { - journeys.produce(); - } catch (Exception e) { - - e.printStackTrace(); - } - - Journey journey = new Journey(); - String journeyID = "CO23143"; - String origin = "Copenhagen"; - String destination = "Oslo"; - journey.setJourneyID(journeyID); - journey.setOrigin(origin); - journey.setDestination(destination); - - try { - journeys.pull(); - journeys.create(journey); - journeys.push(); - } catch (Exception e) { - - e.printStackTrace(); - } - ContainerDatabase containers = new ContainerDatabase(); - int quantity = 11; - String location = "Copenhagen"; - String contentType = "fish"; - String company = "Banana Company"; - int temperature = 20; - int humidity = 21; - int pressure = 22; - - for (int i = 1 ; i <= quantity; i++) { - containers.getContainers().add(new Container()); - containers.getContainers().get(i - 1).setContainerID(i); - containers.getContainers().get(i - 1).setPosition(location); - containers.getContainers().get(i - 1).setAvailability(true); - containers.getContainers().get(i - 1).setTemperature(temperature); - containers.getContainers().get(i - 1).setHumidity(humidity); - containers.getContainers().get(i - 1).setPressure(pressure); - containers.getContainers().get(i - 1).appendHistory(); - containers.getContainers().get(i - 1).appendHistory(); - containers.getContainers().get(i - 1).appendHistory(); - } - - Client client = new Client(); - client.setId(100); - client.registerContainers(origin, contentType, company, quantity, containers); - journeys.registerTo(journeyID, origin, destination, client.getMyContainers()); - - try { - journeys.push(); - journeys.pull(); - journeys.push(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - -} diff --git a/System/src/main/java/clientsManagement/Client.java b/System/src/main/java/clientsManagement/Client.java deleted file mode 100644 index a731ce6..0000000 --- a/System/src/main/java/clientsManagement/Client.java +++ /dev/null @@ -1,165 +0,0 @@ -package clientsManagement; - -import java.util.ArrayList; -import journeysManagement.Container; -import journeysManagement.ContainerDatabase; -import journeysManagement.ResponseObject; - -public class Client { - - private String name = null; - private int BirthDate; - private String email = null; - private int PhoneNumber = 0; - private String ReferencePerson; - private String Address; - private int id; - private ArrayList myContainers = new ArrayList(); - - public Client(String name, int BirthDate, String email, int PhoneNumber) { - this.name= name; - this.BirthDate = BirthDate; - this.email = email; - this.PhoneNumber = PhoneNumber; - } - - public Client(String name, int BirthDate, int PhoneNumber) { - this.name= name; - this.BirthDate = BirthDate; - this.PhoneNumber = PhoneNumber; - } - - public Client(String name, int BirthDate, String email) { - this.name= name; - this.BirthDate = BirthDate; - this.email = email; - } - - public Client(String name, int BirthDate, String email, int PhoneNumber,String ReferencePerson , String Address) { - this.name= name; - this.BirthDate = BirthDate; - this.email = email; - this.PhoneNumber = PhoneNumber; - this.Address = Address; - this.ReferencePerson = ReferencePerson; - } - - public Client() { - super(); - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - public int getBirthDate() { - return BirthDate; - } - public void setBirthDate(int birthDate) { - BirthDate = birthDate; - } - - - public String getEmail() { - return email; - } - public void setEmail(String email) { - this.email = email; - } - - - public int getPhoneNumber() { - return PhoneNumber; - } - public void setPhoneNumber(int phoneNumber) { - PhoneNumber = phoneNumber; - } - - - public String getReferencePerson() { - return ReferencePerson; - } - - public void setReferencePerson(String referencePerson) { - ReferencePerson = referencePerson; - } - - - public String getAddress() { - return Address; - } - - public void setAddress(String address) { - Address = address; - } - - - public String toString() { - return "The Id is: "+ this.id +"\n"+ "The name is: "+this.name +"\n" + "this is the address" + this.Address ; - } - - - public void update(String email, int PhoneNumber,String ReferencePerson , String Address, Registery registery) { - - if (registery.allowedUpdate(email, PhoneNumber)) { - this.email = email; - this.PhoneNumber = PhoneNumber; - this.Address = Address; - this.ReferencePerson = ReferencePerson; - } - - } - - public ArrayList getMyContainers() { - return myContainers; - } - - public void setMyContainers(ArrayList myContainers) { - this.myContainers = myContainers; - } - - public ResponseObject registerContainers(String location, String contentType, String company, int quantity, ContainerDatabase containers) { - - ResponseObject response; - - if (!((location == null) || (contentType == null) || (company == null) || (quantity == 0))){ - - response = new ResponseObject(111, "Container not found"); - - for (Container container : containers.extract(quantity, location)) { - container.setOwner(id); - container.setContentType(contentType); - container.setCompany(company); - this.myContainers.add(container); - // Codes from 000 to 099 indicate successful operation - response = new ResponseObject(010, "Container has been registered"); - } - - } - - else { - - // Codes from 100 to 999 indicate otherwise - response = new ResponseObject(110, "Necessary parameters not entered"); - - } - - return response; - - } - -} diff --git a/System/src/main/java/clientsManagement/Registery.java b/System/src/main/java/clientsManagement/Registery.java deleted file mode 100644 index fd84c23..0000000 --- a/System/src/main/java/clientsManagement/Registery.java +++ /dev/null @@ -1,121 +0,0 @@ -package clientsManagement; - - -import java.util.ArrayList; - -public class Registery { - private int count = 1; - - - - private ArrayList registery = new ArrayList (); - - - public void addClient(Client c) { - if (this.checkContactInfoOfClients(c)== 0 & c.getName() != null & (c.getEmail() !=null | c.getPhoneNumber() != 0)) { - c.setId(count); - registery.add(c); - count++; - - }else { - - } - - - } - - public boolean ClientExists(Client c) { - - return (checkInstancesofClientinRegistery(c) == 1); - - } - - public boolean checkID(Client c) { - int uniqueId = c.getId(); - int counter = 0; - for (Client clients : registery) { - if (clients.getId()==uniqueId) { - counter ++; - } - } - return (counter == 1); - } - //name is misleading - public int checkContactInfoOfClients(Client c) { - int counter = 0; - for (Client clients : registery) { - if (clients.getPhoneNumber()== c.getPhoneNumber() | clients.getEmail() == c.getEmail()) { - counter ++; - } - } - return (counter); - } - public void printer() { - for (Client clients : registery) { - System.out.println(clients); - } - } - - public int checkInstancesofClientinRegistery(Client c) { - int counter = 0; - for (Client clients : registery) { - if (clients.getPhoneNumber()== c.getPhoneNumber() & clients.getEmail() == c.getEmail() & clients.getId() == c.getId() & clients.getBirthDate() == c.getBirthDate() & clients.getName() == c.getName() ) { - counter ++; - } - } - return (counter); - } - - public boolean checkUpdatedInfo(String name, int BirthDate, String email, int PhoneNumber,String ReferencePerson , String Address) { - for (Client clients : registery) { - if (clients.getPhoneNumber()== PhoneNumber & clients.getEmail() == email & clients.getBirthDate() == BirthDate & clients.getName() == name & clients.getReferencePerson() == ReferencePerson & clients.getAddress() == Address) { - return true; - } - } - return (false); - - - } - - public boolean allowedUpdate(String email, int PhoneNumber) { - for (Client clients : registery) { - if (clients.getPhoneNumber() == PhoneNumber ) { - return false; - }else if (clients.getEmail() == email){ - return false; - - } - } - return true; - } - - - public ArrayList getInfoClientbyId(int Id) { - ArrayList listOfClientMatchingId = new ArrayList (); - for (Client clients : registery) { - if (clients.getId() == Id) { - listOfClientMatchingId.add(clients); - } - } - return listOfClientMatchingId; - } - - - - public ArrayList getInfoClientbyName(String name) { - ArrayList listOfClientMatchingName = new ArrayList (); - for (Client clients : registery) { - if (clients.getName() == name) { - listOfClientMatchingName.add(clients); - } - } - return listOfClientMatchingName; - } -} - - - - - - - diff --git a/System/src/main/java/containerStatusTracking/Class.java b/System/src/main/java/containerStatusTracking/Class.java deleted file mode 100644 index e8856f7..0000000 --- a/System/src/main/java/containerStatusTracking/Class.java +++ /dev/null @@ -1,5 +0,0 @@ -package containerStatusTracking; - -public class Class { - -} diff --git a/System/src/main/java/controller/AddHistorycontroller.java b/System/src/main/java/controller/AddHistorycontroller.java new file mode 100644 index 0000000..5cbeb6a --- /dev/null +++ b/System/src/main/java/controller/AddHistorycontroller.java @@ -0,0 +1,97 @@ + +package controller; + +import java.util.ArrayList; + +import javax.swing.JOptionPane; + +import management.Container; +import management.LogisticsCompany; +import view.MainMenuCompanyView; +import view.AddHistoryView; +import view.ContainerErrorGUI; +import view.DisplayClientsView; +import view.DisplayContainersView; +//import view.DisplayJourneysView; +public class AddHistorycontroller { + + private LogisticsCompany logisticCompany; + private Session sessionModel; + private AddHistoryView view; + + + public AddHistorycontroller(LogisticsCompany logisticCompany, Session session) { + this.logisticCompany = logisticCompany; + this.sessionModel = session; + } + + /** + * @param date + * @param id + * @param temp + * @param humid + * @param press + * + * this method finds the specified container, and appends the new data to its history + * in case of not finding the container it returns an error pop up + */ + public void submitChanges(String date, int id, int temp, int humid, int press) { + + + + ArrayList containers = new ArrayList(); + containers = logisticCompany.getContainerDatabase().getContainers(); + + int count = 0; + for(int i = 0; i < containers.size(); i++) { + + + if (containers.get(i).getContainerID() == id) { + + containers.get(i).setDate(date); + + containers.get(i).setTemperature(temp); + + containers.get(i).setHumidity(humid); + + containers.get(i).setPressure(press); + + //containers.get(i).setPosition(pos); + //containers.get(i).setPosition(containers.get(i).getPosition()); + + containers.get(i).appendHistory(); + + containers.get(i).setHumidity(humid); + count++; + view.setVisible(false); + try { + System.out.println("Pushing"); + logisticCompany.getContainerDatabase().push(); + } catch (Exception e) { + + e.printStackTrace(); + } + + + + + } + } + if (count == 0) { + + new ContainerErrorGUI(); + + } + + } + + public void setView(AddHistoryView view) { + this.view = view; + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + +} \ No newline at end of file diff --git a/System/src/main/java/controller/ApplicationController.java b/System/src/main/java/controller/ApplicationController.java new file mode 100644 index 0000000..6c8e860 --- /dev/null +++ b/System/src/main/java/controller/ApplicationController.java @@ -0,0 +1,79 @@ +package controller; + +import java.awt.Color; + +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; + +import management.Client; +import management.ClientDatabase; +import management.LogisticsCompany; + +import view.MainMenuClientView; +import view.MainMenuCompanyView; + +public class ApplicationController { + // Attributes + private Client client; + private LogisticsCompany logisticsCompany; + private LoginController loginController; + private MainMenuClientController mainMenuClientController; + private MainMenuCompanyController mainMenuCompanyController; + private ClientDatabase clientDataBase; + + // Constructor + public ApplicationController() { + logisticsCompany = LogisticsCompany.getInstance(); + clientDataBase = logisticsCompany.getClientDatabase(); + } + + // Sends to the login page + public void login() { + loginController = new LoginController(this); + loginController.display(); + } + // Sends to the main menu page either the company's or the client's + public void mainMenu(Session session){ + if (session.getRole().equals("Company")) { + mainMenuCompanyController = new MainMenuCompanyController(this.logisticsCompany, session); + + MainMenuCompanyView mainMenuView = new MainMenuCompanyView(this.mainMenuCompanyController); + mainMenuCompanyController.setView(mainMenuView); + mainMenuCompanyController.display(); + } + + else { + this.client = clientDataBase.getClient(session.getUsername()).get(0); + mainMenuClientController = new MainMenuClientController(this.client, this.logisticsCompany, session); + + MainMenuClientView mainMenuView = new MainMenuClientView(this.mainMenuClientController); + mainMenuClientController.setView(mainMenuView); + mainMenuClientController.display(); + } + + } + + + // Getter + public ClientDatabase getclientdatabase() { + return this.clientDataBase; + } + + // main + public static void main(String[] args) { + try { + for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + UIManager.setLookAndFeel(info.getClassName()); + UIManager.put("control", new Color(255,255,255)); + UIManager.put("nimbusBlueGrey", new Color(115,164,209)); + break; + } + } + } catch (Exception e) { + } + ApplicationController app = new ApplicationController(); + app.login(); + } + +} diff --git a/System/src/main/java/controller/ClientPersonalInfoController.java b/System/src/main/java/controller/ClientPersonalInfoController.java new file mode 100644 index 0000000..47b7108 --- /dev/null +++ b/System/src/main/java/controller/ClientPersonalInfoController.java @@ -0,0 +1,80 @@ +package controller; + + + +import java.util.regex.Pattern; + +import javax.swing.JOptionPane; + +import management.Client; + + +import management.LogisticsCompany; +import view.ClientPersonalInfoView; + + + +public class ClientPersonalInfoController { + + //Attributes + private Session sessionModel; + private ClientPersonalInfoView view; + private Client client; + private LogisticsCompany company; + + //Constructor + public ClientPersonalInfoController(Client client, Session session, LogisticsCompany company) { + this.client = client; + this.company = company; + this.sessionModel = session; + } + + + //Setter + public void setView(ClientPersonalInfoView view) { + this.view = view; + this.view.setSession(sessionModel); + } + + + //Method used to check for right format and gets access to the model (Client class) in order to update personal information + public void updateInfo(String FirstName, String LastName, String BirthDate, String Email, String PhoneNumber, String password ) throws Exception { +// boolean birthdayFormatChecker = Pattern.matches("([0-9]{2})\\\\([0-9]{2})\\\\([0-9]{4})", BirthDate); + boolean birthdayFormatChecker = Pattern.matches("^((3[0-1]|2[0-9]|1[0-9]|[1-9])/(1[0-2]|0[1-9])/([0-9]{4}))$", BirthDate); + boolean emailFormatChecker = Pattern.matches("^(.+)@(.+)$", Email); + boolean phoneFormatChecker = Pattern.matches("([0-9]{8,}+)", PhoneNumber); + boolean nameFormatChecker = Pattern.matches("^[^\\d\\s]+$",FirstName) & Pattern.matches("^[^\\d\\s]+$",LastName); + boolean passwordFormatChecker = Pattern.matches("^[^\\s]+$",password); + if (birthdayFormatChecker & emailFormatChecker & phoneFormatChecker& nameFormatChecker& passwordFormatChecker) { + String errorMessage = client.updateInfo(FirstName, LastName, BirthDate, Email, PhoneNumber, company.getClientDatabase()).getErrorMessage(); + client.updateInfo(password, company.getClientDatabase()); + view.showError(errorMessage); + } + else if(!birthdayFormatChecker) { + view.showError("Incorrect birth date format! It has to follow the following format DD/MM/YYYY"); + }else if(!emailFormatChecker) { + view.showError("Incorrect email format! It has to follow the following XXXXX@XXXX.XXX"); + }else if(!phoneFormatChecker) { + view.showError("Incorrect phone format! It has to be composed of at least 8 numbers with no other characters"); + }else if(!nameFormatChecker) { + view.showError("Incorrect name format! Numbers and white spaces are not allowed"); + }else if(!passwordFormatChecker) { + view.showError("Incorrect password format! No white space is allowed"); + }else { + view.showError("ERROR ERROR!! DOWNLOADING VIRUS!!!"); + } + + + } + //Displays the personal information page for client + public void display() { + view.setVisible(true); + } + //getter + public Client getClient() { + return this.client; + } + + +} + diff --git a/System/src/main/java/controller/CompanyPersonalInfoController.java b/System/src/main/java/controller/CompanyPersonalInfoController.java new file mode 100644 index 0000000..99f3201 --- /dev/null +++ b/System/src/main/java/controller/CompanyPersonalInfoController.java @@ -0,0 +1,84 @@ +package controller; + +import java.util.regex.*; +import management.Client; + +import management.LogisticsCompany; +import response.ResponseObject; +import view.CompanyPersonalInfoView; +import view.DisplayClientsView; + + + + + public class CompanyPersonalInfoController { + //Attributes + private Session sessionModel; + private CompanyPersonalInfoView view; + + private LogisticsCompany company; + //Constructor + public CompanyPersonalInfoController( Session session, LogisticsCompany company) { + + this.company =company; + this.sessionModel = session; + } + //setter + public void setView(CompanyPersonalInfoView view) { + this.view = view; + this.view.setSession(sessionModel); + } + //Method used to check for right fomat and gets access to the model (LogisticsCompany class) in order to register a client + public void createInfo(String FirstName, String LastName, String BirthDate, String Email, String PhoneNumber, String password ) throws Exception { +// boolean birthdayFormatChecker = Pattern.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})", BirthDate); + boolean birthdayFormatChecker = Pattern.matches("^((3[0-1]|2[0-9]|1[0-9]|[1-9])/(1[0-2]|0[1-9])/([0-9]{4}))$", BirthDate); + boolean EmailFormatChecker = Pattern.matches("^(.+)@(.+)$", Email); + boolean phoneFormatChecker = Pattern.matches("([0-9]{8,}+)", PhoneNumber); + boolean nameFormatChecker = Pattern.matches("^[^\\d\\s]+$",FirstName) & Pattern.matches("^[^\\d\\s]+$",LastName); + boolean passwordFormatChecker = Pattern.matches("^[^\\s]+$",password); + + if (birthdayFormatChecker & EmailFormatChecker & phoneFormatChecker& nameFormatChecker& passwordFormatChecker) { + Client client = new Client(FirstName, LastName, BirthDate, Email, PhoneNumber, password); + ResponseObject result = company.CreateNewClient(client); + if (result.getErrorCode() == 1000) { + view.setVisible(false); + view.showError(result.getErrorMessage()); + + DisplayClientsController displayClientsController = new DisplayClientsController(this.company, this.sessionModel); + + DisplayClientsView invView = new DisplayClientsView(displayClientsController); + displayClientsController.setView(invView); + displayClientsController.display(); + } else { + view.showError(result.getErrorMessage()); + } + }else if(!birthdayFormatChecker) { + view.showError("Incorrect birth date format! It has to follow the following format DD/MM/YYYY"); + }else if(!EmailFormatChecker) { + view.showError("Incorrect email format! It has to follow the following XXXXX@XXXX.XXX"); + }else if(!phoneFormatChecker) { + view.showError("Incorrect phone format! It has to be composed of at least 8 numbers with no other characters"); + }else if(!nameFormatChecker) { + view.showError("Incorrect name format! Numbers and white spaces are not allowed"); + }else if(!passwordFormatChecker) { + view.showError("Incorrect password format! No white space is allowed"); + }else { + view.showError("ERROR ERROR!! DOWNLOADING VIRUS!!!"); + } + + + } + + + //Display the company personal information page + + public void display() { + view.setVisible(true); + } + + + } + + + + diff --git a/System/src/main/java/controller/DisplayClientsController.java b/System/src/main/java/controller/DisplayClientsController.java new file mode 100644 index 0000000..bd41713 --- /dev/null +++ b/System/src/main/java/controller/DisplayClientsController.java @@ -0,0 +1,92 @@ +package controller; + + +import javax.swing.JOptionPane; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import management.LogisticsCompany; +import management.ClientDatabase; +import view.CompanyPersonalInfoView; +import view.DisplayClientsView; + +public class DisplayClientsController { + //Attributes + private LogisticsCompany logisticCompany; + private Session sessionModel; + private DisplayClientsView view; + private JTextField id = new JTextField(); + private JTextField email = new JTextField(); + + private ClientDatabase registery = new ClientDatabase(); + Object [] fields = { + "ID", id, + "Email", email, + + + }; + //Constructor + public DisplayClientsController(LogisticsCompany logisticCompany, Session session) { + registery.setClients(logisticCompany.getClientDatabase().getClients()); + this.sessionModel = session; + this.logisticCompany = logisticCompany; + } + //Filters the table based on some criteria (id or email) + public void filter() { + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String id = this.id.getText(); + String email = this.email.getText(); + + + if (response==0) { + + registery.setClients(logisticCompany.getClientDatabase().getClients()); + + if (!id.equals("") && id!=null) { + registery.setClients((registery.getClient(Integer.parseInt(id)))); + SwingUtilities.updateComponentTreeUI(view); + + } + + if (!email.equals("") && email!=null) { + registery.setClients((registery.getClient(email))); + SwingUtilities.updateComponentTreeUI(view); + + + } + + }} + + + //Sends to create client page + public void addClient() { + view.setVisible(false); + + CompanyPersonalInfoController companyInfoController = new CompanyPersonalInfoController(this.sessionModel,logisticCompany); + + CompanyPersonalInfoView companyView = new CompanyPersonalInfoView(companyInfoController); + companyInfoController.setView(companyView); + companyInfoController.display(); + + + } + //Setter + public void setView(DisplayClientsView view) { + this.view = view; + this.view.setTableModel(registery); + this.view.setSession(sessionModel); + } + //Refreshes the table so you cancel the filter + public void refresh() { + registery.setClients(logisticCompany.getClientDatabase().getClients()); + SwingUtilities.updateComponentTreeUI(view); + + + } + //Displays the display client page + public void display() { + view.setVisible(true); + } + +} diff --git a/System/src/main/java/controller/DisplayContainersController.java b/System/src/main/java/controller/DisplayContainersController.java new file mode 100644 index 0000000..45a7430 --- /dev/null +++ b/System/src/main/java/controller/DisplayContainersController.java @@ -0,0 +1,125 @@ + +package controller; + +import javax.swing.JComboBox; +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.ContainerDatabase; +import management.LogisticsCompany; +import view.DisplayContainersView; + +public class DisplayContainersController { + + private LogisticsCompany logisticCompany; + private Session sessionModel; + private DisplayContainersView view; + private ContainerDatabase registry = new ContainerDatabase(); + private JTextField id = new JTextField(); + private JTextField owner = new JTextField(); + private JTextField position = new JTextField(); + private JTextField contentType = new JTextField(); + private JTextField company = new JTextField(); + private Boolean comboBoxItems[] = {null, Boolean.TRUE, Boolean.FALSE}; + private JComboBox availability = new JComboBox(comboBoxItems); + + Object [] fields = { + "ID", id, + "Current Owner", owner, + "Position", position, + "Content Type", contentType, + "Company", company, + "Availability", availability + }; + + public DisplayContainersController(LogisticsCompany logisticCompany, Session session) { + registry.setContainers(logisticCompany.getContainerDatabase().getContainers()); + this.sessionModel = session; + this.logisticCompany = logisticCompany; + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String containerID = this.id.getText(); + String owner = this.owner.getText(); + String position = this.position.getText(); + String contentType = this.contentType.getText(); + String company = this.company.getText(); + Boolean availability = (Boolean) this.availability.getSelectedItem(); + + if (response==0) { + + registry.setContainers(logisticCompany.getContainerDatabase().getContainers()); + + if (!containerID.equals("") && containerID!=null) { + registry.setContainers(registry.find("containerID", Integer.parseInt(containerID))); + } + + if (!owner.equals("") && owner!=null) { + registry.setContainers(registry.find("owner", Integer.parseInt(owner))); + } + + if (!position.equals("") && position!=null) { + registry.setContainers(registry.find("position", position)); + } + + if (!contentType.equals("") && contentType!=null) { + registry.setContainers(registry.find("contentType", contentType)); + } + + if (!company.equals("") && company!=null) { + registry.setContainers(registry.find("company", company)); + } + + if (availability!=null) { + registry.setContainers(registry.find(availability)); + } + + } + } + + public void register() { + String newProduct = JOptionPane.showInputDialog("Please insert the location:"); + if(newProduct != null && !newProduct.equals("")){ + logisticCompany.getContainerDatabase().register(newProduct); + registry.setContainers(logisticCompany.getContainerDatabase().getContainers()); + } + } + + public void findAvailable() { + registry.setContainers(logisticCompany.getContainerDatabase().find(true)); + } + + public void delete(int selectedRow) { + if (selectedRow >= 0) { + logisticCompany.getContainerDatabase().getContainers().remove(selectedRow); + registry.setContainers(logisticCompany.getContainerDatabase().getContainers()); + } + } + + public void refresh() { + registry.setContainers(logisticCompany.getContainerDatabase().getContainers()); + } + + public void save() throws Exception { + int reply = JOptionPane.showConfirmDialog(null, "Are you sure you would like to save changes permanetly?", "Warning", JOptionPane.YES_NO_OPTION); + if (reply == JOptionPane.YES_OPTION) { + logisticCompany.getContainerDatabase().push(); + } + } + + public void setView(DisplayContainersView view) { + this.view = view; + this.view.setTableModel(registry); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + } + diff --git a/System/src/main/java/controller/DisplayJourneyContainersClientController.java b/System/src/main/java/controller/DisplayJourneyContainersClientController.java new file mode 100644 index 0000000..8f3c4d7 --- /dev/null +++ b/System/src/main/java/controller/DisplayJourneyContainersClientController.java @@ -0,0 +1,108 @@ +package controller; + +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.Client; +import management.ContainerDatabase; +import management.Journey; +import management.LogisticsCompany; +import view.DisplayJourneyContainersClientView; +import view.HistoryView; + +public class DisplayJourneyContainersClientController { + + private Client client; + private Session sessionModel; + private DisplayJourneyContainersClientView view; + private Journey key; + private ContainerDatabase registry = new ContainerDatabase(); + private JTextField id = new JTextField(); + private JTextField position = new JTextField(); + private JTextField contentType = new JTextField(); + + private LogisticsCompany company; + + Object [] fields = { + "ID", id, + "Position", position, + "Content Type", contentType, + }; + + public DisplayJourneyContainersClientController(Client client, Session session, int selectedRow, LogisticsCompany company) { + String journeyID = (String) client.getMyJourneys().getValueAt(selectedRow, 0); + String origin = (String) client.getMyJourneys().getValueAt(selectedRow, 1); + String destination = (String) client.getMyJourneys().getValueAt(selectedRow, 2); + + this.company = company; + + for (Journey key : client.getMyJourneys().getJourneys().keySet()) { + if (key.getJourneyID().equals(journeyID) && key.getOrigin().equals(origin) && key.getDestination().equals(destination)) { + this.registry.setContainers(client.getMyJourneys().getJourneys().get(key)); + this.client = client; + this.sessionModel = session; + this.key = key; + break; + } + } + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String containerID = this.id.getText(); + String position = this.position.getText(); + String contentType = this.contentType.getText(); + + if (response==0) { + + if (!containerID.equals("") && containerID!=null) { + registry.setContainers(registry.find("containerID", Integer.parseInt(containerID))); + } + + if (!position.equals("") && position!=null) { + registry.setContainers(registry.find("position", position)); + } + + if (!contentType.equals("") && contentType!=null) { + registry.setContainers(registry.find("contentType", contentType)); + } + + } + } + + public void showHistory(int selectedRow) { + if (selectedRow >= 0) { + + int id = (int) registry.getValueAt(selectedRow, 0); + HistoryController historyController; + System.out.println(this.company.toString()); + + historyController = new HistoryController(this.company, this.sessionModel, id); + + HistoryView invView = new HistoryView(historyController); + historyController.setView(invView); + historyController.display(); + + + } + } + + public void refresh() { + registry.setContainers(client.getMyJourneys().getJourneys().get(key)); + } + + public void setView(DisplayJourneyContainersClientView invView) { + this.view = invView; + this.view.setTableModel(registry); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + } + diff --git a/System/src/main/java/controller/DisplayJourneyContainersCompanyController.java b/System/src/main/java/controller/DisplayJourneyContainersCompanyController.java new file mode 100644 index 0000000..94df585 --- /dev/null +++ b/System/src/main/java/controller/DisplayJourneyContainersCompanyController.java @@ -0,0 +1,108 @@ +package controller; + +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.LogisticsCompany; +import view.DisplayJourneyContainersCompanyView; + +public class DisplayJourneyContainersCompanyController { + + private LogisticsCompany logisticCompany; + private Session sessionModel; + private DisplayJourneyContainersCompanyView view; + private Journey key; + private ContainerDatabase registry = new ContainerDatabase(); + private JTextField ID = new JTextField(); + private JTextField owner = new JTextField(); + private JTextField contentType = new JTextField(); + private JTextField company = new JTextField(); + + Object [] fields = { + "ID", ID, + "Current Owner", owner, + "Content type", contentType, + "Company", company, + }; + + public DisplayJourneyContainersCompanyController(LogisticsCompany logisticCompany, Session session, int selectedRow) { + String journeyID = (String) logisticCompany.getJourneyDatabase().getValueAt(selectedRow, 0); + String origin = (String) logisticCompany.getJourneyDatabase().getValueAt(selectedRow, 1); + String destination = (String) logisticCompany.getJourneyDatabase().getValueAt(selectedRow, 2); + + for (Journey key : logisticCompany.getJourneyDatabase().getJourneys().keySet()) { + if (key.getJourneyID().equals(journeyID) && key.getOrigin().equals(origin) && key.getDestination().equals(destination)) { + this.registry.setContainers(logisticCompany.getJourneyDatabase().getJourneys().get(key)); + this.logisticCompany = logisticCompany; + this.sessionModel = session; + this.key = key; + break; + } + } + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String containerID = this.ID.getText(); + String owner = this.owner.getText(); + String contentType = this.contentType.getText(); + String company = this.company.getText(); + + if (response==0) { + + registry.setContainers(logisticCompany.getJourneyDatabase().getJourneys().get(key)); + + if (!containerID.equals("") && containerID!=null) { + registry.setContainers(registry.find("containerID", Integer.parseInt(containerID))); + } + + if (!owner.equals("") && owner!=null) { + registry.setContainers(registry.find("owner", Integer.parseInt(owner))); + } + + if (!contentType.equals("") && contentType!=null) { + registry.setContainers(registry.find("contentType", contentType)); + } + + if (!company.equals("") && company!=null) { + registry.setContainers(registry.find("company", company)); + } + + } + } + + public void remove(int selectedRow) { + if (selectedRow >= 0) { + int containerID = (int) registry.getValueAt(selectedRow, 0); + logisticCompany.getJourneyDatabase().removeContainer(key.getJourneyID(), containerID); + for (Container container: logisticCompany.getContainerDatabase().getContainers()) { + if (container.getContainerID() == containerID) { + container.setCurrentJourney(""); + } + } + registry.setContainers(logisticCompany.getJourneyDatabase().getJourneys().get(key)); + } + } + + public void refresh() { + registry.setContainers(logisticCompany.getJourneyDatabase().getJourneys().get(key)); + } + + public void setView(DisplayJourneyContainersCompanyView view) { + this.view = view; + this.view.setTableModel(registry); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + } + diff --git a/System/src/main/java/controller/DisplayJourneysClientController.java b/System/src/main/java/controller/DisplayJourneysClientController.java new file mode 100644 index 0000000..5813900 --- /dev/null +++ b/System/src/main/java/controller/DisplayJourneysClientController.java @@ -0,0 +1,107 @@ +package controller; + +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.Client; +import management.JourneyDatabase; +import management.LogisticsCompany; +import view.DisplayJourneyContainersClientView; +import view.DisplayJourneysClientView; + +public class DisplayJourneysClientController { + + private Client client; + private Session sessionModel; + private DisplayJourneysClientView view; + private JourneyDatabase registry = new JourneyDatabase(); + DisplayJourneyContainersCompanyController displayJourneyContainersController; + private JTextField id = new JTextField(); + private JTextField origin = new JTextField(); + private JTextField destination = new JTextField(); + private JTextField departureDate = new JTextField(); + private JTextField arrivalDate = new JTextField(); + //////////// + private LogisticsCompany company; + + Object [] fields = { + "ID", id, + "Origin", origin, + "Destination", destination, + "Departure Date", departureDate, + "Arrival Date", arrivalDate + }; + + public DisplayJourneysClientController(Client client, Session session, LogisticsCompany company) { + registry.setJourneys(client.getMyJourneys().getJourneys()); + this.client = client; + this.sessionModel = session; + this.company = company; + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String journeyID = this.id.getText(); + String origin = this.origin.getText(); + String destination = this.destination.getText(); + String departureDate = this.departureDate.getText(); + String arrivalDate = this.arrivalDate.getText(); + + if (response==0) { + + registry.setJourneys(client.getMyJourneys().getJourneys()); + + if (!journeyID.equals("") && journeyID!=null) { + registry.setJourneys(client.getMyJourneys().find("journeyID", journeyID)); + } + + if (!origin.equals("") && origin!=null) { + registry.setJourneys(client.getMyJourneys().find("origin", origin)); + } + + if (!destination.equals("") && destination!=null) { + registry.setJourneys(client.getMyJourneys().find("destination", destination)); + } + + if (!departureDate.equals("") && departureDate!=null) { + registry.setJourneys(client.getMyJourneys().find("departureDate", departureDate)); + } + + if (!arrivalDate.equals("") && arrivalDate!=null) { + registry.setJourneys(client.getMyJourneys().find("arrivalDate", arrivalDate)); + } + + } + } + + public void showContainers(int selectedRow) { + if (selectedRow >= 0) { + DisplayJourneyContainersClientController displayContainersController = new DisplayJourneyContainersClientController(this.client, this.sessionModel, selectedRow, this.company); + System.out.println(this.company.toString()); + + DisplayJourneyContainersClientView invView = new DisplayJourneyContainersClientView(displayContainersController); + displayContainersController.setView(invView); + displayContainersController.display(); + } + } + + public void refresh() { + registry.setJourneys(client.getMyJourneys().getJourneys()); + } + + + public void setView(DisplayJourneysClientView invView) { + this.view = invView; + this.view.setTableModel(registry); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + } + + diff --git a/System/src/main/java/controller/DisplayJourneysCompanyController.java b/System/src/main/java/controller/DisplayJourneysCompanyController.java new file mode 100644 index 0000000..71db03a --- /dev/null +++ b/System/src/main/java/controller/DisplayJourneysCompanyController.java @@ -0,0 +1,231 @@ +package controller; + +import java.util.regex.Pattern; + +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.LogisticsCompany; +import management.Container; +import management.Journey; +import management.JourneyDatabase; +import view.DisplayJourneyContainersCompanyView; +import view.DisplayJourneysCompanyView; + +public class DisplayJourneysCompanyController { + + private LogisticsCompany logisticsCompany; + private Session sessionModel; + private DisplayJourneysCompanyView view; + private JourneyDatabase registry = new JourneyDatabase(); + private DisplayJourneyContainersCompanyController displayJourneyContainersController; + private JTextField id = new JTextField(); + private JTextField origin = new JTextField(); + private JTextField destination = new JTextField(); + private JTextField departureDate = new JTextField(); + private JTextField arrivalDate = new JTextField(); + + Object [] fields = { + "ID", id, + "Origin", origin, + "Destination", destination, + "Departure Date", departureDate, + "Arrival Date", arrivalDate + }; + + Object [] fields2 = { + "Origin", origin, + "Destination", destination, + "Departure date", departureDate, + "Arrival Date", arrivalDate + }; + + public DisplayJourneysCompanyController(LogisticsCompany logisticsCompany, Session session) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + this.logisticsCompany = logisticsCompany; + this.sessionModel = session; + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String journeyID = this.id.getText(); + String origin = this.origin.getText(); + String destination = this.destination.getText(); + String departureDate = this.departureDate.getText(); + String arrivalDate = this.arrivalDate.getText(); + + if (response==0) { + + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + + if (!journeyID.equals("") && journeyID!=null) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().find("journeyID", journeyID)); + } + + if (!origin.equals("") && origin!=null) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().find("origin", origin)); + } + + if (!destination.equals("") && destination!=null) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().find("destination", destination)); + } + + if (!departureDate.equals("") && departureDate!=null) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().find("departureDate", departureDate)); + } + + if (!arrivalDate.equals("") && arrivalDate!=null) { + registry.setJourneys(logisticsCompany.getJourneyDatabase().find("arrivalDate", arrivalDate)); + } + + } + } + + public void showContainers(int selectedRow) { + if (selectedRow >= 0) { + displayJourneyContainersController = new DisplayJourneyContainersCompanyController(this.logisticsCompany, this.sessionModel, selectedRow); + + DisplayJourneyContainersCompanyView invView = new DisplayJourneyContainersCompanyView(displayJourneyContainersController); + displayJourneyContainersController.setView(invView); + displayJourneyContainersController.display(); + } + } + + public void updatePosition(int selectedRow) { + if (selectedRow >= 0) { + String journeyID = (String) registry.getValueAt(selectedRow, 0); + String position = JOptionPane.showInputDialog("Enter updated position:"); + + if(position != null && position.equals("")) { + view.showError2(); + } + + else if(position != null && !position.equals("")) { + logisticsCompany.getJourneyDatabase().updatePosition(journeyID, position); + logisticsCompany.getContainerDatabase().updatePosition(journeyID, position); + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + } + } + } + + public void setDeparture(int selectedRow) { + if (selectedRow >= 0) { + String journeyID = (String) registry.getValueAt(selectedRow, 0); + String date = JOptionPane.showInputDialog("Enter departure date:"); + + if(date!=null) { + boolean dateFormatChecker = Pattern.matches("^((3[0-1]|2[0-9]|1[0-9]|[1-9])/(1[0-2]|0[1-9])/([0-9]{4}))$", date); + if(dateFormatChecker) { + logisticsCompany.getJourneyDatabase().setDeparture(journeyID, date); + } + + else { + view.showError3(); + } + } + + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + + } + } + + public void arrived(int selectedRow) { + if (selectedRow >= 0) { + String journeyID = (String) registry.getValueAt(selectedRow, 0); + + logisticsCompany.getJourneyDatabase().markArrived(journeyID); + logisticsCompany.getContainerDatabase().markArrived(journeyID); + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + + } + } + + public void add() { + + int response = JOptionPane.showConfirmDialog(null, fields2, "Enter relevant details", JOptionPane.OK_CANCEL_OPTION); + + String origin = this.origin.getText(); + String destination = this.destination.getText(); + String departureDate = this.departureDate.getText(); + String arrivalDate = this.arrivalDate.getText(); + + Journey journey = new Journey(); + journey.setJourneyDatabase(logisticsCompany.getJourneyDatabase()); + + if (response==0) { + + if(!(origin.equals("") || origin==null || destination.equals("") || destination==null)) { + + journey.setOrigin(origin); + journey.setDestination(destination); + + if (!departureDate.equals("") && departureDate!=null && Pattern.matches("^((3[0-1]|2[0-9]|1[0-9]|[1-9])/(1[0-2]|0[1-9])/([0-9]{4}))$", departureDate)) { + journey.setDepartureDate(departureDate); + + if (!arrivalDate.equals("") && arrivalDate!=null && Pattern.matches("^((3[0-1]|2[0-9]|1[0-9]|[1-9])/(1[0-2]|0[1-9])/([0-9]{4}))$", arrivalDate)) { + journey.setArrivalDate(arrivalDate); + journey.setJourneyID(journey.createJourneyID()); + logisticsCompany.getJourneyDatabase().create(journey); + } + else { + view.showError3(); + } + + } + else { + view.showError3(); + } + + } + else { + view.showError(); + } + + } + + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + + } + + public void delete(int selectedRow) { + if (selectedRow >= 0) { + String journeyID = (String) registry.getValueAt(selectedRow, 0); + logisticsCompany.getJourneyDatabase().complete(journeyID); + for (Container container : logisticsCompany.getContainerDatabase().find("journeyID", journeyID)) { + container.setAvailability(true); + container.setOwner(0); + container.setCurrentJourney(""); + container.setCompany(""); + container.setContentType(""); + } + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + } + } + + public void refresh() { + registry.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + } + + public void save() throws Exception { + int reply = JOptionPane.showConfirmDialog(null, "Are you sure you would like to save changes permanetly?", "Warning", JOptionPane.YES_NO_OPTION); + if (reply == JOptionPane.YES_OPTION) { + logisticsCompany.getJourneyDatabase().push(); + logisticsCompany.getContainerDatabase().push(); + } + } + + public void setView(DisplayJourneysCompanyView invView) { + this.view = invView; + this.view.setTableModel(registry); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + } + + diff --git a/System/src/main/java/controller/DisplayJourneysRegisterController.java b/System/src/main/java/controller/DisplayJourneysRegisterController.java new file mode 100644 index 0000000..01d5b71 --- /dev/null +++ b/System/src/main/java/controller/DisplayJourneysRegisterController.java @@ -0,0 +1,109 @@ +package controller; + +import java.util.ArrayList; + +import javax.swing.JOptionPane; +import javax.swing.JTextField; + +import management.Client; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.JourneyDatabase; +import management.LogisticsCompany; +import view.DisplayJourneysRegisterView; + +public class DisplayJourneysRegisterController { + + private Client client; + private LogisticsCompany logisticCompany; + private Session sessionModel; + private DisplayJourneysRegisterView view; + private Object[] input; + private JourneyDatabase registryJ = new JourneyDatabase(); + private JourneyDatabase registryJbackup = new JourneyDatabase(); + private ContainerDatabase registryC = new ContainerDatabase(); + private JTextField id = new JTextField(); + private JTextField departureDate = new JTextField(); + private JTextField arrivalDate = new JTextField(); + + Object [] fields = { + "ID", id, + "Departure date", departureDate, + "Arrival date", arrivalDate, + }; + + public DisplayJourneysRegisterController(Client client, LogisticsCompany logisticCompany, JourneyDatabase registryJ, ContainerDatabase registryC, Object[] input, Session session) { + this.client = client; + this.logisticCompany = logisticCompany; + this.registryJ = registryJ; + this.registryJbackup.setJourneys(registryJ.getJourneys());; + this.registryC = registryC; + this.input = input; + this.sessionModel = session; + } + + public void find() { + + int response = JOptionPane.showConfirmDialog(null, fields, "Enter relevant search criteria", JOptionPane.OK_CANCEL_OPTION); + + String journeyID = this.id.getText(); + String departureDate = this.departureDate.getText(); + String arrivalDate = this.arrivalDate.getText(); + + if (response==0) { + + registryJ.setJourneys(registryJ.getJourneys()); + + if (!journeyID.equals("") && journeyID!=null) { + registryJ.setJourneys(registryJ.find("journeyID", journeyID)); + } + + if (!departureDate.equals("") && departureDate!=null) { + registryJ.setJourneys(registryJ.find("departureDate", departureDate)); + } + + if (!arrivalDate.equals("") && arrivalDate!=null) { + registryJ.setJourneys(registryJ.find("arrivalDate", arrivalDate)); + } + + } + } + + public void refresh() { + registryJ.setJourneys(registryJbackup.getJourneys()); + } + + public void select(int selectedRow) throws Exception { + Journey journey = new Journey(); + journey.setJourneyID(registryJ.getValueAt(selectedRow, 0)); + journey.setOrigin(registryJ.getValueAt(selectedRow, 1)); + journey.setDestination(registryJ.getValueAt(selectedRow, 2)); + journey.setDepartureDate(registryJ.getValueAt(selectedRow, 3)); + journey.setArrivalDate(registryJ.getValueAt(selectedRow, 4)); + + int reply = JOptionPane.showConfirmDialog(null, "Are you sure you would like to register containers to this journey?", "Registration cannot be undone", JOptionPane.YES_NO_OPTION); + if (reply == JOptionPane.YES_OPTION) { + registryC.book(client.getId(), (String) input[0], (String) input[1], (String) input[2], (int) input[3]); + registryJ.registerTo(journey.getJourneyID(), journey.getOrigin(), journey.getDestination(), registryC.getContainers()); + logisticCompany.getJourneyDatabase().push(); + logisticCompany.getContainerDatabase().push(); + view.showConfirmation("Your container(s) have been successfuly registered to journey " + journey.getJourneyID()); + view.setVisible(false); + } + + } + + public void setView(DisplayJourneysRegisterView invView) { + this.view = invView; + this.view.setTableModel(registryJ); + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + } + + diff --git a/System/src/main/java/controller/DisplayRegisterController.java b/System/src/main/java/controller/DisplayRegisterController.java new file mode 100644 index 0000000..4ef5021 --- /dev/null +++ b/System/src/main/java/controller/DisplayRegisterController.java @@ -0,0 +1,109 @@ +package controller; + +import javax.swing.JOptionPane; + +import management.Client; +import management.ContainerDatabase; +import management.JourneyDatabase; +import management.LogisticsCompany; +import view.DisplayJourneysRegisterView; +import view.DisplayRegisterView; + +public class DisplayRegisterController { + + private Client client; + private LogisticsCompany logisticsCompany; + private Session sessionModel; + private DisplayJourneysRegisterController displayJourneysController; + private DisplayRegisterView view; + private JourneyDatabase registryJ = new JourneyDatabase(); + private ContainerDatabase registryC = new ContainerDatabase(); + + public DisplayRegisterController(Client client, LogisticsCompany logisticsCompany, Session session) { + this.client = client; + this.logisticsCompany = logisticsCompany; + this.sessionModel = session; + } + + public void request(String origin, String destination, String company, String contentType, String numberOfContainers) { + + String input = "Missing input:\n"; + String info = ""; + registryJ.setJourneys(logisticsCompany.getJourneyDatabase().getJourneys()); + + if (!origin.isEmpty() && origin != null) { + registryJ.setJourneys(registryJ.find("origin", origin)); + } + else { + info += "- Origin\n"; + } + + if (!destination.isEmpty() && destination != null) { + registryJ.setJourneys(registryJ.find("destination", destination)); + } + else { + info += "- Destination\n"; + } + + if (company.isEmpty() || company == null) { + info += "- Company\n"; + } + + if (contentType.isEmpty() || contentType == null) { + info += "- Content Type\n"; + } + + if (numberOfContainers.isEmpty() || numberOfContainers == null) { + info += "- Number of Containers\n"; + } + + if (info.isEmpty()) { + if (registryJ.getJourneys().isEmpty()) { + view.showError("Your desired journey was not found"); + } + else { + int number = Integer.valueOf(numberOfContainers); + this.registryC.setContainers(logisticsCompany.getContainerDatabase().getContainers()); + this.registryC.setContainers(registryC.extract(number, origin)); + int size = registryC.getContainers().size(); + int reply = JOptionPane.YES_OPTION; + + if (size > 0) { + if (size != number) { + reply = JOptionPane.showConfirmDialog(null, "There are only " + size + " containers available in " + origin + ". Would you like to proceed with " + size + " containers instead?", "Warning", JOptionPane.YES_NO_OPTION); + } + + if (reply == JOptionPane.YES_OPTION) { + Object [] inputFields = {origin, contentType, company, number}; + displayJourneysController = new DisplayJourneysRegisterController(this.client, this.logisticsCompany, this.registryJ, this.registryC, inputFields, this.sessionModel); + + DisplayJourneysRegisterView invView = new DisplayJourneysRegisterView(displayJourneysController); + view.setVisible(false); + displayJourneysController.setView(invView); + displayJourneysController.display(); + } + } + else { + view.showError("Unfortunately, there are no more available containers in " + origin); + } + } + } + else { + view.showError(input + info); + } + + } + + public void setView(DisplayRegisterView invView) { + this.view = invView; + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + } + + diff --git a/System/src/main/java/controller/FriendsMainMenuController.java b/System/src/main/java/controller/FriendsMainMenuController.java new file mode 100644 index 0000000..b8e83ce --- /dev/null +++ b/System/src/main/java/controller/FriendsMainMenuController.java @@ -0,0 +1,57 @@ +package controller; + +import javax.swing.JOptionPane; +import management.Client; +import management.ClientDatabase; +import management.LogisticsCompany; +import response.ResponseObject; +import view.DisplayJourneysClientView; +import view.FriendsMainMenuView; + +public class FriendsMainMenuController { + //Attributes + private LogisticsCompany logisticCompany; + private Session sessionModel; + private FriendsMainMenuView view; + private ClientDatabase registery = new ClientDatabase() ; + private Client client; + //Construcotrs + public FriendsMainMenuController(Client client, LogisticsCompany logisticCompany, Session session) { + registery.setClients(client.getMyFriends(logisticCompany.getClientDatabase())); + this.client = client; + this.sessionModel = session; + this.logisticCompany = logisticCompany; + } + + //adds friends + public void friendAdding() { + String newProduct = JOptionPane.showInputDialog("Please insert the email of the client who you want to share infomation with:"); + ResponseObject result = client.addFriend(newProduct, logisticCompany.getClientDatabase()); + view.showError(result.getErrorMessage()); + } + //sends to friends jounreys page + public void showJourneys(int selectedRow) { + if (selectedRow >= 0) { + //we figure out the friend from the selectedRow + String email = (String) (registery.getValueAt(selectedRow, 4)); + Client theFriend = registery.getClient(email).get(0); + theFriend.getMyJourneys().setJourneys(this.logisticCompany.getJourneyDatabase().extract(theFriend.getId())); + DisplayJourneysClientController displayJourneysController = new DisplayJourneysClientController(theFriend, this.sessionModel, this.logisticCompany); + DisplayJourneysClientView invView = new DisplayJourneysClientView(displayJourneysController); + displayJourneysController.setView(invView); + displayJourneysController.display(); + + } + } + //setter + public void setView(FriendsMainMenuView view) { + this.view = view; + this.view.setTableModel(registery); + this.view.setSession(sessionModel); + } + //diplays friends main menu page + public void display() { + view.setVisible(true); + } + +} diff --git a/System/src/main/java/controller/HistoryController.java b/System/src/main/java/controller/HistoryController.java new file mode 100644 index 0000000..7bbf1e9 --- /dev/null +++ b/System/src/main/java/controller/HistoryController.java @@ -0,0 +1,69 @@ +package controller; + +import java.util.ArrayList; + +import management.Container; +import management.LogisticsCompany; +import view.HistoryView; + +public class HistoryController { + + + private LogisticsCompany logisticCompany; + //private Session sessionModel; + private HistoryView view; + private int containerId; + + + public HistoryController(LogisticsCompany logisticCompany, Session session, int id) { + this.logisticCompany = logisticCompany; + //this.sessionModel = session; + this.containerId = id; + } + + public void setView(HistoryView view) { + this.view = view; + //this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + /** + * this method returns a matrix of data history + * each column refers to a measurement + * @return matrix of container data history + */ + public Object[][] history() { + + ArrayList containers = new ArrayList(); + containers = logisticCompany.getContainerDatabase().getContainers(); + + + int count = 0; + for(int i = 0; i < containers.size(); i++) { + + if (containers.get(i).getContainerID() == this.containerId) { + + + return containers.get(i).getHistory().showTable(); + + + + } + + + + } + + return null; + } + + + + + + } + diff --git a/System/src/main/java/controller/LoginController.java b/System/src/main/java/controller/LoginController.java new file mode 100644 index 0000000..a8979a0 --- /dev/null +++ b/System/src/main/java/controller/LoginController.java @@ -0,0 +1,35 @@ +package controller; + +import controller.User; +import view.LoginView; + +public class LoginController { + //Attributes + private ApplicationController application; + private Session session; + private LoginView view; + //Constructor + public LoginController(ApplicationController application) { + this.application = application; + this.session = new Session(); + this.view = new LoginView(this); + } + //Checks if password and username match + public void validateCredentials(String username, String password) { + User user = new User(); + user.setUsername(username); + user.load(application.getclientdatabase()); + if ((!username.isEmpty()) && user.passwordMatches(password)) { + session.setUser(user); + session.setRole(user); + view.setVisible(false); + application.mainMenu(session); + } else { + view.showError(); + } + } + //Displays the login view + public void display() { + view.setVisible(true); + } +} diff --git a/System/src/main/java/controller/MainMenuClientController.java b/System/src/main/java/controller/MainMenuClientController.java new file mode 100644 index 0000000..b44d6fd --- /dev/null +++ b/System/src/main/java/controller/MainMenuClientController.java @@ -0,0 +1,74 @@ +package controller; + +import management.Client; +import management.LogisticsCompany; +import view.ClientPersonalInfoView; +import view.DisplayJourneysClientView; +import view.DisplayRegisterView; +import view.FriendsMainMenuView; +import view.MainMenuClientView; + +public class MainMenuClientController { + //Attributes + private Client client; + private LogisticsCompany logisticsCompany; + private Session sessionModel; + private MainMenuClientView MainMenuview; + + //Constructor + public MainMenuClientController(Client client, LogisticsCompany logisticsCompany, Session session) { + this.client = client; + this.logisticsCompany = logisticsCompany; + this.sessionModel = session; + } + //Setter + public void setView(MainMenuClientView MainMenuview) { + this.MainMenuview = MainMenuview; + this.MainMenuview.setSession(sessionModel); + } + //Displays The main menu for clients + public void display() { + MainMenuview.setVisible(true); + } + //sends to display journeys for clients + + public void displayJourneys() { + this.client.getMyJourneys().setJourneys(this.logisticsCompany.getJourneyDatabase().extract(client.getId())); + DisplayJourneysClientController displayJourneysController = new DisplayJourneysClientController(this.client, this.sessionModel, this.logisticsCompany); + DisplayJourneysClientView invView = new DisplayJourneysClientView(displayJourneysController); + displayJourneysController.setView(invView); + displayJourneysController.display(); + } + //sends to register containers for clients + + public void register() { + DisplayRegisterController displayRegisterController = new DisplayRegisterController(this.client, this.logisticsCompany, this.sessionModel); + DisplayRegisterView invView = new DisplayRegisterView(displayRegisterController); + displayRegisterController.setView(invView); + displayRegisterController.display(); + } + //Sends to Friends main menu page + public void friend() { + FriendsMainMenuController friendsMainMenuController = new FriendsMainMenuController(this.client, this.logisticsCompany,this.sessionModel); + + FriendsMainMenuView clientView = new FriendsMainMenuView(friendsMainMenuController); + friendsMainMenuController.setView(clientView); + friendsMainMenuController.display(); + } + //Sends to page for updating personal information + public void updateInfo() { + ClientPersonalInfoController clientInfoController = new ClientPersonalInfoController(this.client, this.sessionModel, this.logisticsCompany); + + ClientPersonalInfoView clientView = new ClientPersonalInfoView(clientInfoController); + clientInfoController.setView(clientView); + clientInfoController.display(); + } + //Getter + public Client getClient() { + return client; + } + + } + + + diff --git a/System/src/main/java/controller/MainMenuCompanyController.java b/System/src/main/java/controller/MainMenuCompanyController.java new file mode 100644 index 0000000..0e9c7b9 --- /dev/null +++ b/System/src/main/java/controller/MainMenuCompanyController.java @@ -0,0 +1,85 @@ +package controller; + +import management.LogisticsCompany; +import view.MainMenuCompanyView; +import view.SeeHistoryView; +import view.AddHistoryView; +import view.DisplayClientsView; +import view.DisplayContainersView; +import view.DisplayJourneysCompanyView; + +public class MainMenuCompanyController { + //Attributes + private LogisticsCompany logisticsCompany; + private Session sessionModel; + private MainMenuCompanyView MainMenuview; + private DisplayClientsController displayClientsController; + private DisplayContainersController displayContainersController; + private DisplayJourneysCompanyController displayJourneysController; + private AddHistorycontroller addHistorycontroller; + private SeeHistoryController seeHistoryController; + //Constructor + public MainMenuCompanyController(LogisticsCompany logisticCompany, Session session) { + this.logisticsCompany = logisticCompany; + this.sessionModel = session; + } + //setter + public void setView(MainMenuCompanyView MainMenuview) { + this.MainMenuview = MainMenuview; + this.MainMenuview.setSession(sessionModel); + } + //Displays the company's main menu page + public void display() { + MainMenuview.setVisible(true); + } + + //Sends to display clients page + public void displayClients() { + displayClientsController = new DisplayClientsController(this.logisticsCompany, this.sessionModel); + + DisplayClientsView invView = new DisplayClientsView(displayClientsController); + displayClientsController.setView(invView); + displayClientsController.display(); + } + //Sends to display containers page + public void displayContainers() { + displayContainersController = new DisplayContainersController(this.logisticsCompany, this.sessionModel); + + DisplayContainersView invView = new DisplayContainersView(displayContainersController); + displayContainersController.setView(invView); + displayContainersController.display(); + } + //Sends to display journeys page + + public void displayJourneys() { + displayJourneysController = new DisplayJourneysCompanyController(this.logisticsCompany, this.sessionModel); + + DisplayJourneysCompanyView invView = new DisplayJourneysCompanyView(displayJourneysController); + displayJourneysController.setView(invView); + displayJourneysController.display(); + } + //Sends to display History page + + public void displayAddHistory() { + addHistorycontroller = new AddHistorycontroller(this.logisticsCompany, this.sessionModel); + + AddHistoryView invView = new AddHistoryView(addHistorycontroller); + addHistorycontroller.setView(invView); + addHistorycontroller.display(); + + + } + //Sends to see History page + + public void displaySeeHistory() { + seeHistoryController = new SeeHistoryController(this.logisticsCompany, this.sessionModel); + + SeeHistoryView invView = new SeeHistoryView(seeHistoryController); + seeHistoryController.setView(invView); + seeHistoryController.display(); + } + + } + + + diff --git a/System/src/main/java/controller/SeeHistoryController.java b/System/src/main/java/controller/SeeHistoryController.java new file mode 100644 index 0000000..d8b078e --- /dev/null +++ b/System/src/main/java/controller/SeeHistoryController.java @@ -0,0 +1,93 @@ +package controller; + +import java.util.ArrayList; + +import management.Container; +import management.LogisticsCompany; +import view.AddHistoryView; +import view.ContainerErrorGUI; +import view.HistoryView; +import view.SeeHistoryView; + +public class SeeHistoryController { + + + + private LogisticsCompany logisticCompany; + private Session sessionModel; + private SeeHistoryView view; + + + + public SeeHistoryController(LogisticsCompany logisticCompany, Session session) { + this.logisticCompany = logisticCompany; + this.sessionModel = session; + } + + public void setView(SeeHistoryView view) { + this.view = view; + this.view.setSession(sessionModel); + } + + public void display() { + view.setVisible(true); + } + + + + /** + * @param id + * this method finds the specified container and opens a new window containing data history + * if container is not found, it opens an error pop up + */ + public void showHistory(int id) { + + ArrayList containers = new ArrayList(); + containers = logisticCompany.getContainerDatabase().getContainers(); + + + int count = 0; + for(int i = 0; i < containers.size(); i++) { + + + if (containers.get(i).getContainerID() == id) { + + // pass the id to the next view / controller combo + + HistoryController historyController; + + historyController = new HistoryController(this.logisticCompany, this.sessionModel, id); + + HistoryView invView = new HistoryView(historyController); + historyController.setView(invView); + historyController.display(); + + + count++; + view.setVisible(false); + + } + + + + + + } + + if (count == 0) { + + new ContainerErrorGUI(); + + } + + + } + + + + + + + + +} diff --git a/System/src/main/java/controller/Session.java b/System/src/main/java/controller/Session.java new file mode 100644 index 0000000..6bd69a4 --- /dev/null +++ b/System/src/main/java/controller/Session.java @@ -0,0 +1,32 @@ +package controller; +import controller.User; + +public final class Session { + //Attributes + private User user; + private String role; + //Constructor + public Session() { + } + //setters and getters + public void setUser(User user) { + this.user = user; + } + + public void setRole(User user) { + if (user.getUsername().equals("company")) { + this.role = "Company"; + } else { + this.role = "Client"; + } + } + + public String getUsername() { + return user.getUsername(); + } + + public String getRole() { + return role; + } + +} diff --git a/System/src/main/java/controller/User.java b/System/src/main/java/controller/User.java new file mode 100644 index 0000000..780baa8 --- /dev/null +++ b/System/src/main/java/controller/User.java @@ -0,0 +1,40 @@ +package controller; + +import management.ClientDatabase; + +public final class User { + //Attributes + private String username; + private String password; + //setters and getters + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + //Fetches the username's password + public void load(ClientDatabase c) { + + if (this.username.equals("company")) { + this.password = username; + + } + + else { + + this.password = c.getPassword(this.username); + } + + } + //Checks if the given password matches the password from the database + public boolean passwordMatches(String password) { + if (this.password == null | password == null ) { + return false; + }else { + return (this.password.equals(password)); + } + } + +} diff --git a/System/src/main/java/journeysManagement/Company.java b/System/src/main/java/journeysManagement/Company.java deleted file mode 100644 index 6362dc7..0000000 --- a/System/src/main/java/journeysManagement/Company.java +++ /dev/null @@ -1,44 +0,0 @@ -package journeysManagement; - -public class Company { - - String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public ResponseObject updatePosition(String journeyID, String position, JourneyDatabase journeys) { - - ResponseObject response = new ResponseObject(140, "Journey not found");; - - for(Journey key : journeys.getJourneys().keySet()) { - - if (key.getJourneyID().equals(journeyID)) { - - response = new ResponseObject(111, "Container not found");; - - for (Container container : journeys.getJourneys().get(key)) { - container.setPosition(position); - response = new ResponseObject(070, "Position has been updated"); - } - - } - - } - - return response; - -} - -//List list = ... -// for (Employee e : list) -// if (e.getID() == id) -// return true; -// return false; - -} diff --git a/System/src/main/java/journeysManagement/Container.java b/System/src/main/java/journeysManagement/Container.java deleted file mode 100644 index 50d24d2..0000000 --- a/System/src/main/java/journeysManagement/Container.java +++ /dev/null @@ -1,97 +0,0 @@ -package journeysManagement; - -public class Container { - - private int containerID; - private int owner; - private String position; - private String contentType; - private String company; - private boolean availability; - private int temperature; - private int humidity; - private int pressure; - private HistoryBook history; - - public Container() { - super(); - history = new HistoryBook(); - } - - public int getContainerID() { - return containerID; - } - public void setContainerID(int containerID) { - this.containerID = containerID; - } - - public int getOwner() { - return owner; - } - public void setOwner(int owner) { - this.owner = owner; - } - - - public String getPosition() { - return position; - } - public void setPosition(String position) { - this.position = position; - } - - - public String getContentType() { - return contentType; - } - public void setContentType(String contentType) { - this.contentType = contentType; - } - - - public String getCompany() { - return company; - } - public void setCompany(String company) { - this.company = company; - } - - public boolean isAvailability() { - return availability; - } - public void setAvailability(boolean availability) { - this.availability = availability; - } - - public int getPressure() { - return this.pressure; - } - public void setPressure(int pressure) { - this.pressure = pressure; - } - - public int getHumidity() { - return this.humidity; - } - public void setHumidity(int humidity) { - this.humidity = humidity; - } - - public int getTemperature() { - return this.temperature; - } - public void setTemperature(int temperature) { - this.temperature = temperature; - } - - public HistoryBook getHistory() { - return history; - } - public void setHistory(HistoryBook history) { - this.history = history; - } - public void appendHistory() { - this.history.add(temperature, humidity, pressure, position); - } - -} diff --git a/System/src/main/java/journeysManagement/ContainerDatabase.java b/System/src/main/java/journeysManagement/ContainerDatabase.java deleted file mode 100644 index b13e77d..0000000 --- a/System/src/main/java/journeysManagement/ContainerDatabase.java +++ /dev/null @@ -1,45 +0,0 @@ -package journeysManagement; - -import java.util.ArrayList; - -public class ContainerDatabase { - - private ArrayList containers; - - public ContainerDatabase() { - this.setContainers(new ArrayList()); - } - - public ArrayList getContainers() { - return containers; - } - - public void setContainers(ArrayList containerList) { - this.containers = containerList; - } - - public ArrayList extract(int number, String position) { - - ArrayList extract = new ArrayList(); - - int count = number; - for(Container container: containers) { - - if (container.getPosition().equals(position) && container.isAvailability() == true && count > 0) { - container.setAvailability(false); - extract.add(container); - count -= 1; - } - - - } - - if (extract.size() < number) { - System.out.println("WARNING: " + extract.size() + " containers are available"); - } - - return extract; - - } - -} diff --git a/System/src/main/java/journeysManagement/HistoryBook.java b/System/src/main/java/journeysManagement/HistoryBook.java deleted file mode 100644 index c80463e..0000000 --- a/System/src/main/java/journeysManagement/HistoryBook.java +++ /dev/null @@ -1,52 +0,0 @@ -package journeysManagement; - -import java.util.ArrayList; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import java.time.Instant; - -public class HistoryBook { - - private ArrayList date; - private ArrayList temperature; - private ArrayList humidity; - private ArrayList pressure; - private ArrayList position; - - - public HistoryBook() { - super(); - date = new ArrayList(); - temperature = new ArrayList(); - humidity = new ArrayList(); - pressure = new ArrayList(); - position = new ArrayList(); - } - - @JsonCreator - @SuppressWarnings("unchecked") - public HistoryBook(Object[][] history) { - date = (ArrayList) history[0][0]; - temperature = (ArrayList) history[1][0]; - humidity = (ArrayList) history[2][0]; - pressure = (ArrayList) history[3][0]; - position = (ArrayList) history[4][0]; - } - - @JsonValue - public Object[][] show() { - Object table[][] = {{date},{temperature},{humidity},{pressure},{position}}; - return table; - } - - public void add(int temperature, int humidity, int pressure, String position) { - // this.date.add(Instant.now()); - this.temperature.add(temperature); - this.humidity.add(humidity); - this.pressure.add(pressure); - this.position.add(position); - } - -} diff --git a/System/src/main/java/journeysManagement/JourneyDatabase.java b/System/src/main/java/journeysManagement/JourneyDatabase.java deleted file mode 100644 index eb915fb..0000000 --- a/System/src/main/java/journeysManagement/JourneyDatabase.java +++ /dev/null @@ -1,177 +0,0 @@ -package journeysManagement; - -import java.util.Map; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -public class JourneyDatabase { - - final String database = "journey_database.json"; - - @JsonProperty("journeys") - @JsonSerialize(keyUsing = JourneySerializer.class) - @JsonDeserialize(keyUsing = JourneyDeserializer.class) - private Map> journeys; - - @JsonCreator - public JourneyDatabase() { - this.journeys = new HashMap>(); - } - - public Map> getJourneys() { - return journeys; - } - - public void setJourneys(Map> journeys) { - this.journeys = journeys; - } - - public void produce() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - JourneyDatabase journeys = new JourneyDatabase(); - String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(journeys); - Files.write(Paths.get(database), jsonResult.getBytes()); - } - - - public void pull() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - JourneyDatabase journeys = new JourneyDatabase(); - - journeys = mapper.readValue(new File(database), JourneyDatabase.class); - this.journeys = journeys.getJourneys(); - - } - - public void push() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - JourneyDatabase journeys = new JourneyDatabase(); - journeys.setJourneys(this.getJourneys()); - String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(journeys); - Files.write(Paths.get(database), jsonResult.getBytes()); - } - - public ResponseObject create(Journey journey) { - - ResponseObject response; - ArrayList containerList; - - if(!((journey.getOrigin() == null) || (journey.getOrigin() == null))){ - - containerList = new ArrayList(); - getJourneys().put(journey, containerList); - // Codes from 000 to 100 indicate successful operation - response = new ResponseObject(012, "Journey has been created"); - - } - - else { - - // Codes from 100 to 999 indicate otherwise - response = new ResponseObject(120, "Necessary parameters not entered"); - - } - - return response; - - } - - public ResponseObject registerTo(String journeyID, String origin, String destination, ArrayList containerList) { - - ResponseObject response = new ResponseObject(140, "Journey not found"); - - if (containerList.size() == 0) { - - response = new ResponseObject(111, "Container not found"); - - } else { - - for (Journey key : journeys.keySet()) { - if (key.getJourneyID().equals(journeyID) && key.getOrigin().equals(origin) && key.getDestination().equals(destination)) { - for (Container container : containerList) { - journeys.get(key).add(container); - response = new ResponseObject(014, "Container has been assigned to a journey"); - } - } - } - - } - - return response; - - } - - // Generic Map filter, with predicate - public Map filter(Map map, Predicate predicate) { - return map.entrySet() - .stream() - .filter(x -> predicate.test(x.getValue())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - public Map find(int clientID, String criteria, String entry) { - - Map myContainers = new HashMap(); - - for (Journey key : journeys.keySet()) { - for (Container container : journeys.get(key)) { - if (container.getOwner() == clientID) { - myContainers.put(container, key); - } - } - } - - if (criteria.equals("origin")) { - myContainers = filter(myContainers, journey -> journey.getOrigin().equals(entry)); - } - - else if (criteria.equals("destination")) { - myContainers = filter(myContainers, journey -> journey.getDestination().equals(entry)); - } - - else if (criteria.equals("content-type")) { - myContainers.entrySet().removeIf(key -> !(key.getKey().getContentType().equals(entry))); - } - - else if (criteria.equals("company")) { - myContainers.entrySet().removeIf(key -> !(key.getKey().getCompany().equals(entry))); - } - - return myContainers; - - } - -// -// public ResponseObject complete(String journeyID) { -// -// ResponseObject response; -// JourneyDatabase companyJourneys = new JourneyDatabase(); -// -// companyJourneys.setRecord(this.record.filter(this.record.getRecord(), container -> container.getCompany().contains(this.manager))); -// if (companyJourneys.getRecord().containsKey(journeyID)) { -// -// this.record.getRecord().remove(journeyID); -// response = new ResponseObject(050, "Journey has been completed and succesfully removed from the record"); -// -// } else { -// -// response = new ResponseObject(700, "Journey was not found"); -// -// }; -// -// return response; -// -//} - -} \ No newline at end of file diff --git a/System/src/main/java/journeysManagement/UML.ucls b/System/src/main/java/journeysManagement/UML.ucls deleted file mode 100644 index 0116cf4..0000000 --- a/System/src/main/java/journeysManagement/UML.ucls +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/System/src/main/java/management/Client.java b/System/src/main/java/management/Client.java new file mode 100644 index 0000000..5d551d5 --- /dev/null +++ b/System/src/main/java/management/Client.java @@ -0,0 +1,210 @@ +package management; + +import java.util.ArrayList; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import response.ResponseObject; + + +public class Client { + //Clients attributes: + private int id; + private String firstName; + private String lastName; + private String birthDate; + private String email; + private String password; + private String phoneNumber ; + + private ArrayList myContainers = new ArrayList(); + private JourneyDatabase myJourneys = new JourneyDatabase(); + + @JsonProperty("friends") + private ArrayList myFriends = new ArrayList(); + + + //Constructors + public Client() { + super(); + } + + public Client(String firstName, String lastName, String BirthDate, String email, String PhoneNumber) { + this.firstName= firstName; + this.lastName= lastName; + this.birthDate = BirthDate; + this.email = email; + this.phoneNumber = PhoneNumber; + this.password = BirthDate; + + } + public Client(String firstName, String lastName, String BirthDate, String email, String PhoneNumber, String password) { + this.firstName= firstName; + this.lastName= lastName; + this.birthDate = BirthDate; + this.email = email; + this.phoneNumber = PhoneNumber; + this.password = password; + + } + //getters and setters + public int getId() { + return id; + } + @JsonProperty("id") + public void setId(int id) { + this.id = id; + } + + public String getfirstName() { + return this.firstName; + } + @JsonProperty("fistName") + public void setfirstName(String name) { + this.firstName=name; + } + + public String getlastName() { + return this.lastName; + } + @JsonProperty("lastName") + public void setlastName(String name) { + this.lastName=name; + } + + public String getBirthDate() { + return birthDate; + } + @JsonProperty("birthDate") + public void setBirthDate(String birthDate) { + this.birthDate = birthDate; + } + + public String getEmail() { + return email; + } + @JsonProperty("email") + public void setEmail(String email) { + this.email = email; + } + + public String getPhoneNumber() { + return phoneNumber; + } + @JsonProperty("phoneNumber") + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + + public String getPassword() { + return password; + } + @JsonProperty("password") + public void setPassword(String password) { + this.password = password; + } + + public ArrayList getMyContainers() { + return myContainers; + } + public void setMyContainers(ArrayList myContainers) { + this.myContainers = myContainers; + } + + public JourneyDatabase getMyJourneys() { + return myJourneys; + } + public void setMyJourneys(JourneyDatabase myJourneys) { + this.myJourneys = myJourneys; + } + + //The following method returns a response object corresponding to whether the personal information of the client has been updated or not. + //In case we fail to update the information, we return a corresponding error code and message + public ResponseObject updateInfo(String firstName,String lastName, String birthDate, String email, String PhoneNumber, ClientDatabase registery) throws Exception { + ResponseObject response; + + if (registery.allowedUpdate(this.id,email) & registery.allowedUpdate(this.id,PhoneNumber)) { + this.firstName = firstName; + this.lastName = lastName; + this.birthDate = birthDate; + this.email = email; + this.phoneNumber = PhoneNumber; + + response = new ResponseObject(1004, "Information Updated successfully"); + registery.push(); + + } else if(!registery.allowedUpdate(this.id, email) ) { + response = new ResponseObject(1005, "Information not updated. Email already used by an existing client"); + + } else { + response = new ResponseObject(1006, "Information not updated. Phone number already used by an existing client"); + } + + return response; + + } + + //This method is used to change the password + //It could have been just merged wit the method above but the password attribute was not created yet. + public void updateInfo(String password, ClientDatabase registery) { + this.password = password; + try { + registery.push(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + //This method is used to find an existing client in database by an email + //It is used in conjunction with the updateFriendList method to implement the information sharing functionality + //this method is used by the client who want to share their information they do not necessarily have access to the information of who ever they send their info to + public ResponseObject addFriend(String email, ClientDatabase registery) { + + ResponseObject response; + ArrayList theToBeAddedFriend = registery.getClient(email); + if (theToBeAddedFriend.isEmpty()){ + response = new ResponseObject(11021, "Friend not found!!!"); + + } + + + else { + // Codes from 100 to 999 indicate otherwise + theToBeAddedFriend.get(0).updateFriendsList(this.id); + try { + registery.push(); + } catch (Exception e) { + e.printStackTrace(); + } + response = new ResponseObject(11560, "Now you friend can see your information"); + } + + return response; + + } + + //This method is used to update the list of client who this client has access to their information + public void updateFriendsList(int id) { + if (myFriends.contains(id)) {} + else{ + myFriends.add(id); + } + } + + + //This method converts the array list of clients ids into an array list of Clients + public ArrayList getMyFriends(ClientDatabase registery){ + ArrayList ListofFriendClients = new ArrayList(); + for (int friend : this.myFriends) { + ListofFriendClients.add(registery.getClient(friend).get(0)); + + } + return ListofFriendClients; + } + +} + diff --git a/System/src/main/java/management/ClientDatabase.java b/System/src/main/java/management/ClientDatabase.java new file mode 100644 index 0000000..1006ca8 --- /dev/null +++ b/System/src/main/java/management/ClientDatabase.java @@ -0,0 +1,263 @@ +package management; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; + +import javax.swing.event.TableModelListener; +import javax.swing.table.AbstractTableModel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ClientDatabase extends AbstractTableModel { + + private static final long serialVersionUID = 1003884717778953988L; + + final String database = "client_database.json"; + + @JsonProperty("clients") + private ArrayList clients; + + @JsonCreator + public ClientDatabase() { + setClients(new ArrayList ()); + } + + //getters and setters + public ArrayList getClients() { + return clients; + } + + public void setClients(ArrayList clients) { + this.clients = clients; + } + + //This method is used to produce a new database it is also used to remove an existing database and create a new fresh empty database + public void produce() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + this.clients = new ArrayList (); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + //This method is used to fetch the information from the json file to the class + public void pull() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + ClientDatabase clients = new ClientDatabase(); + + clients = mapper.readValue(new File(database), ClientDatabase.class); + this.clients = clients.getClients(); + + } + //This method is used to save the changes in this class to the json file + public void push() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + + + //This method checks if registered client has the same phone number of email as the to be updated one. This is to insure that emails and phonenumbers are unique + public boolean allowedUpdate(int id, String emailOrPhoneNumber) { + for (Client perticularClient : clients) { + if (perticularClient.getEmail().equals(emailOrPhoneNumber) & perticularClient.getId() != id){ + return false; + + }else if(perticularClient.getPhoneNumber().equals(emailOrPhoneNumber) ){ + return false; + } + } + return true; + } + + + //password getter + public String getPassword(String email) { + for (Client perticularClient : clients) { + + if (perticularClient.getEmail().equals(email)) { + return perticularClient.getPassword(); + } + } + return null; + } + + //This method is used by the logistics company to make sure the registed clients all have a unique Email + + public boolean legalEmailToAddClient(Client c) { + int counter = 0; + for (Client perticularClient : clients) { + if (perticularClient.getEmail().equals(c.getEmail())) { + counter ++; + } + } + return (counter == 0 ); + } + //This method is used by the logistics company to make sure the registed clients all have a unique phone nunmber + + public boolean legalPhoneNumberToAddClient(Client c) { + int counter = 0; + + for (Client perticularClient : clients) { + if (perticularClient.getPhoneNumber().equals(c.getPhoneNumber())) { + counter ++; + } + } + return (counter == 0 ); + } + + //The following methods are used for the BDD tests + + public boolean ClientExists(Client c) { + return (checkInstancesofClientinRegistery(c) != 0); + } + + public boolean checkID(Client c) { + int uniqueId = c.getId(); + int counter = 0; + for (Client Client : clients) { + if (Client.getId()==uniqueId) { + counter ++; + } + } + return (counter == 1); + } + + public int checkInstancesofClientinRegistery(Client c) { + int counter = 0; + for (Client Client : clients) { + if (Client.getPhoneNumber()== c.getPhoneNumber() & Client.getEmail() == c.getEmail() & Client.getId() == c.getId() & Client.getBirthDate() == c.getBirthDate() & Client.getfirstName() == c.getfirstName() & Client.getlastName() == c.getlastName() ) { + counter ++; + } + } + return (counter); + } + + public boolean checkUpdatedInfo(String firstName, String lastName, String BirthDate, String email, String PhoneNumber) { + for (Client Client : clients) { + if (Client.getPhoneNumber()== PhoneNumber & Client.getEmail() == email & Client.getBirthDate() == BirthDate & Client.getfirstName() == firstName & Client.getlastName() == lastName ) { + return true; + } + } + return (false); + + + } + + + // The getClient method is overloaded so it is capable of returning a Client array list of all clients who match the searching input + + //For getting clients by Id the output would either be empty or contains one element due to the uniqueness of id + public ArrayList getClient(int Id) { + ArrayList listOfClientMatchingId = new ArrayList (); + for (Client Client : this.getClients()) { + if (Client.getId() == Id) { + listOfClientMatchingId.add(Client); + } + } + return listOfClientMatchingId; + } + + //For getting clients by email the output would either be empty or contains one element due to the uniqueness of email + + public ArrayList getClient(String email) { + ArrayList listOfClientMatchingName = new ArrayList (); + for (Client Client : this.getClients()) { + if (Client.getEmail().equals(email) ) { + listOfClientMatchingName.add(Client); + } + } + return listOfClientMatchingName; + } + //For getting clients by first and last name the output can be an ArrayList of more than one client in case multiple clients have the same name + + public ArrayList getClient(String firstName,String lastName) { + ArrayList listOfClientMatchingName = new ArrayList (); + for (Client Client : this.getClients()) { + if (Client.getfirstName().equals(firstName) & (Client.getlastName().equals(lastName))) { + listOfClientMatchingName.add(Client); + } + } + return listOfClientMatchingName; + } + + + //The following methods are used for defining the Jtable + @JsonIgnore + @Override + public int getRowCount() { + return clients.size(); + } + + @JsonIgnore + public int getColumnCount() { + return 6; + } + @JsonIgnore + @Override + public TableModelListener[] getTableModelListeners() { + return listenerList.getListeners(TableModelListener.class); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + + Client perticularClient = clients.get(rowIndex); + + if (columnIndex == 0) { + return perticularClient.getId(); + + } else if (columnIndex == 1) { + return perticularClient.getfirstName(); + + } else if (columnIndex == 2) { + return perticularClient.getlastName(); + + } else if (columnIndex == 3) { + return perticularClient.getBirthDate(); + + } else if (columnIndex == 4) { + return perticularClient.getEmail(); + + } else if (columnIndex == 5) { + return perticularClient.getPhoneNumber(); + + } else { + return null; + } + + } + + public String getColumnName(int columnIndex) { + + if (columnIndex == 0) { + return "Client ID"; + + } else if (columnIndex == 1) { + return "First name"; + + } else if (columnIndex == 2) { + return "Last name"; + + } else if (columnIndex == 3) { + return "Date of birth"; + + } else if (columnIndex == 4) { + return "Email"; + + } else if (columnIndex == 5) { + return "Phone number"; + + } else { + return null; + } + + } + +} + + + \ No newline at end of file diff --git a/System/src/main/java/management/Container.java b/System/src/main/java/management/Container.java new file mode 100644 index 0000000..e7f9cea --- /dev/null +++ b/System/src/main/java/management/Container.java @@ -0,0 +1,200 @@ +package management; + +/** + * Container class represent single containers used for shipping. + */ + +public class Container { + + private int containerID; + private int owner; + private String position; + private String contentType; + private String company; + private boolean availability; + private String currentJourney; + private int temperature; + private int humidity; + private int pressure; + private String date; + private HistoryBook history; + + /** + * This constructor creates a new history book when introducing a container. + */ + // Container constructor + public Container() { + super(); + history = new HistoryBook(); + } + + /** + * This method returns the container-ID. + * @return container-ID + */ + public int getContainerID() { + return containerID; + } + /** + * This method sets the container-ID. + */ + public void setContainerID(int containerID) { + this.containerID = containerID; + } + + /** + * This method returns the current owner of the container. + * @return owner + */ + public int getOwner() { + return owner; + } + /** + * This method sets the current owner of the container. + */ + public void setOwner(int owner) { + this.owner = owner; + } + + /** + * This method returns the current position of the container. + * @return position + */ + public String getPosition() { + return position; + } + /** + * This method sets the current position of the container. + */ + public void setPosition(String position) { + this.position = position; + } + + /** + * This method returns the content type of the container. + * @return content type + */ + public String getContentType() { + return contentType; + } + /** + * This method sets the content type of the container. + */ + public void setContentType(String contentType) { + this.contentType = contentType; + } + + /** + * This method returns the company using the container. + * @return company + */ + public String getCompany() { + return company; + } + /** + * This method returns sets company using the container. + */ + public void setCompany(String company) { + this.company = company; + } + + /** + * This method returns the availability status of the container. + * @return availability + */ + public boolean isAvailability() { + return availability; + } + /** + * This method returns the availability status of the container. + */ + public void setAvailability(boolean availability) { + this.availability = availability; + } + + /** + * This method returns the current journey of the container. + * @return current journey + */ + public String getCurrentJourney() { + return currentJourney; + } + /** + * This method sets the current journey of the container. + */ + public void setCurrentJourney(String currentJourney) { + this.currentJourney = currentJourney; + } + + /** + * This method returns the current humidity of the container. + * @return humidity + */ + public int getHumidity() { + return this.humidity; + } + /** + * This method sets the current humidity of the container. + */ + public void setHumidity(int humidity) { + this.humidity = humidity; + } + + /** + * This method returns the current temperature of the container. + * @return temperature + */ + public int getTemperature() { + return this.temperature; + } + /** + * This method sets the current temperature of the container. + */ + public void setTemperature(int temperature) { + this.temperature = temperature; + } + + /** + * This method returns the current pressure of the container. + * @return pressure + */ + public int getPressure() { + return this.pressure; + } + /** + * This method sets the current pressure of the container. + */ + public void setPressure(int pressure) { + this.pressure = pressure; + } + + /** + * This method returns the date of container updates. + * @return date + */ + public String getDate() { + return date; + } + /** + * This method sets the date of container updates. + */ + public void setDate(String date) { + this.date = date; + } + + /** + * This method returns the history of the container. + * @return history + */ + public HistoryBook getHistory() { + return history; + } + /** + * This method adds the current values to the history of the container. + * @return history + */ + public void appendHistory() { + this.history.add(date, temperature, humidity, pressure, position); + } + +} diff --git a/System/src/main/java/management/ContainerDatabase.java b/System/src/main/java/management/ContainerDatabase.java new file mode 100644 index 0000000..475a840 --- /dev/null +++ b/System/src/main/java/management/ContainerDatabase.java @@ -0,0 +1,535 @@ +package management; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; + +import javax.swing.event.TableModelListener; +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +import response.ResponseObject; + +/** + * ContainerDatabase class represent all containers that belong to the logistics + * company. It extends AbstractTableModel in order to change the format of the + * container database, which is a array list composed of containers, into a + * table to be used for GUI. + */ + +public class ContainerDatabase extends AbstractTableModel { + + private static final long serialVersionUID = 1003824727758953988L; + + final String database = "container_database.json"; + ObjectMapper mapper = new ObjectMapper(); + + /** + * Json annotations are used for instructing how to both serialize and + * deserialize. + */ + @JsonProperty("containers") + private ArrayList containers; + + /** + * This constructor creates a an array list of containers. + * This is necessary for deserializing. + */ + public ContainerDatabase() { + setContainers(new ArrayList()); + } + + /** + * This method returns the containers. + * @return containers + */ + public ArrayList getContainers() { + return containers; + } + + /** + * This method sets the containers. + */ + public void setContainers(ArrayList containerList) { + this.containers = containerList; + // Notify the view that the data has been changed + fireTableDataChanged(); + } + + /** + * This method produces a container database as a JSON file with name + * "container_database.json" to program's directory by serialising a newly + * created container database object. + */ + public void produce() throws Exception { + mapper = new ObjectMapper(); + ContainerDatabase containers = new ContainerDatabase(); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(containers); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + + /** + * This method pulls the container database from program's directory by + * deserializing "container_database.json" file, and assigning the information + * to containers. + */ + public void pull() throws Exception { + mapper = new ObjectMapper(); + this.containers = mapper.readValue(new File(database), ContainerDatabase.class).getContainers(); + } + + /** + * This method either produces or overwrites an existing container database in + * program's directory with name "container_database.json" by serialising + * containers. + */ + public void push() throws Exception { + mapper = new ObjectMapper(); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + + /** + * This method takes a number, and position as parameters, and returns available + * containers from location equal to the given position. It searches every container + * checking both the position and availability. Once found, it is added to another + * array list of containers. In case if there are no more containers left to + * extract relatively to the number given, then stop extracting, and print out + * a warning message listing the number of how many containers got extracted. + * @return containers + */ + public ArrayList extract(int number, String position) { + + ArrayList extract = new ArrayList(); + int count = number; + + for(Container container: containers) { + if (container.getPosition().equals(position) && container.isAvailability() == true && count > 0) { + extract.add(container); + count -= 1; + } + } + + if (extract.size() < number) { + System.out.println("WARNING: Only " + extract.size() + " containers are available"); + } + + return extract; + + } + + /** + * This method takes a client-ID as a parameter, and returns containers that + * currently belong to the client with the given client-ID. It searches every + * container that have an owner with the same given client-ID. Once found, it + * is added to another array list of containers. This is repeated for every + * container. + * @return containers + */ + public ArrayList extract(int clientID) { + + ArrayList myContainers = new ArrayList(); + + for(Container container: containers) { + if (container.getOwner() == clientID) { + myContainers.add(container); + } + } + + return myContainers; + + } + + /** + * This method takes a client-ID, location, content type, company, and quantity + * and extracts containers according the given location and quantity, and assigns + * them with an owner, content type, and company. It also returns a response about + * the execution of the process. In case if the client-ID is not valid, then + * return a response with a code 132 and a message "Client is not valid". In + * case if the extracted list of containers is empty, then return a response + * with a code 110 and a message "Container is not found". In case if the journey + * attributes are empty, then return a response with a code 210 and a message + * "Necessary parameters are not entered". Otherwise, return a response with + * a code 010 and a message "Container has been registered" for every container + * that gets assigned. + * @return execution response + */ + public ResponseObject book(int clientID, String location, String contentType, String company, int quantity) { + + ResponseObject response; + + if(clientID == 0) { + response = new ResponseObject(132, "Client is not valid"); + } + + else if (!((location == null) || (contentType == null) || (company == null) || (quantity == 0))){ + response = new ResponseObject(110, "Container is not found"); + for (Container container : extract(quantity, location)) { + container.setOwner(clientID); + container.setContentType(contentType); + container.setCompany(company); + container.setAvailability(false); + // Codes from 000 to 099 indicate successful operation + response = new ResponseObject(010, "Container has been registered"); + } + } + + else { + // Codes from 100 to 999 indicate otherwise + response = new ResponseObject(210, "Necessary parameters are not entered"); + } + + return response; + + } + + /** + * This method takes a criteria, and entry as parameters, and returns containers + * that satisfy the criteria based on the entry of type int. According to the + * given criteria, it searches for every container that has a corresponding attribute equal to + * the entry. Once found, this container is added to another array list of + * containers. This is repeated for every container. + * @return containers + */ + public ArrayList find(String criteria, int entry) { + + ArrayList myContainers = new ArrayList(); + + if(criteria!=null) { + if (criteria.equals("containerID")) { + for (Container container : this.containers) { + if (container.getContainerID() == entry) { + myContainers.add(container); + break; + } + } + } + + if (criteria.equals("owner")) { + for (Container container : this.containers) { + if (container.getOwner() == entry) { + myContainers.add(container); + } + } + } + } + + return myContainers; + + } + + /** + * This method takes a criteria, and entry as parameters, and returns containers + * that satisfy the criteria based on the entry of type String. According to the + * given criteria, it searches for every container that has a corresponding + * attribute equal to the entry. Once found, this container is added to another + * array list of containers. This is repeated for every container. + * @return containers + */ + public ArrayList find(String criteria, String entry) { + + entry = StringUtils.lowerCase(entry); + + ArrayList myContainers = new ArrayList(); + + if(criteria != null) { + if (criteria.equals("position")) { + for (Container container : this.containers) { + if (container.getPosition() != null) { + if (StringUtils.lowerCase(container.getPosition()).equals(entry)) { + myContainers.add(container); + } + } + } + } + + if (criteria.equals("contentType")) { + for (Container container : this.containers) { + if (container.getContentType() != null) { + if (StringUtils.lowerCase(container.getContentType()).equals(entry)) { + myContainers.add(container); + } + } + } + } + + if (criteria.equals("company")) { + for (Container container : this.containers) { + if (container.getCompany() != null) { + if (StringUtils.lowerCase(container.getCompany()).equals(entry)) { + myContainers.add(container); + } + } + } + } + + if (criteria.equals("journeyID")) { + for (Container container : this.containers) { + if (container.getCurrentJourney() != null && !container.getCurrentJourney().equals("")) { + if (StringUtils.lowerCase(container.getCurrentJourney().substring(0, 7)).equals(entry)) { + myContainers.add(container); + } + } + } + } + } + + return myContainers; + + } + + /** + * This method takes an entry as parameter, and returns containers that satisfy + * the criteria based on the entry of type boolean. According to the given + * criteria, it searches for every container that has a corresponding attribute + * equal to the entry. Once found, this container is added to another array list + * of containers. This is repeated for every container. + * @return containers + */ + public ArrayList find(boolean entry) { + + ArrayList myContainers = new ArrayList(); + + for (Container container : this.containers) { + if (container.isAvailability() == entry) { + myContainers.add(container); + } + } + + return myContainers; + } + + /** + * This method takes a location as a parameter, and adds a new container with + * a unique container-ID to the container registry. It also returns a response + * about the execution of the process. In case if the location is null, then + * return a response with a code 162 and a message "Location is not valid". + * Otherwise, return a response with a code 010 and a message "Container has + * been registered". + * @return execution response + */ + public ResponseObject register(String location) { + + ResponseObject response = new ResponseObject(162, "Location is not valid"); + + if (location != null) { + int ID; + if (containers.size() == 0) { + ID = 1; + } else { + ID = (containers.get(containers.size()-1).getContainerID() + 1); + } + + Container container = new Container(); + container.setAvailability(true); + container.setCompany(""); + container.setContainerID(ID); + container.setContentType(""); + container.setOwner(0); + container.setPosition(location); + + containers.add(container); + response = new ResponseObject(010, "Container has been registered"); + } + + return response; + + } + + /** + * This method takes a journey-ID, and position as parameters, and searches for + * a container with the current journey equal to the given journey-ID. Once + * found, it updates the position of that container to the given position. + * It also returns a response about the execution of the process. In case if + * the container is not found, then return a response with a code 110 and + * a message "Container is not found". Otherwise, return a response with a + * code 070 and a message "Position has been updated" for every container + * that gets updated. + * @return execution response + */ + public ResponseObject updatePosition(String journeyID, String position) { + + ResponseObject response = new ResponseObject(110, "Container is not found"); + + for (Container container : containers) { + if (container.getCurrentJourney() != null) { + if (container.getCurrentJourney().equals(journeyID)) { + container.setPosition(position); + response = new ResponseObject(070, "Position has been updated"); + } + } + } + + return response; + + } + + /** + * This method takes a journey-ID as a parameter, and searches for a container + * with the current journey equal to the given journey-ID. Once found, it sets + * the current journey of that particular container to "ARRIVED". It also + * returns a response about the execution of the process. In case if the container + * is not found, then return a response with a code 110 and a message "Container + * is not found". Otherwise, return a response with a code 022 and a message + * "Journey label has been updated" for every container that gets updated. + * @return execution response + */ + public ResponseObject markArrived(String journeyID) { + + ResponseObject response = new ResponseObject(110, "Container is not found");; + + for (Container container : containers) { + if (container.getCurrentJourney() != null) { + if (container.getCurrentJourney().equals(journeyID)) { + container.setCurrentJourney(journeyID + ": ARRIVED"); + response = new ResponseObject(022, "Journey label has been updated"); + } + } + } + + return response; + + } + + /** + * This method takes a row index as a parameter, and searches for a container + * with a container-ID equal to the extracted from the indexed container. Once + * found, it removes that container from container registry. It also returns a + * response about the execution of the process. In case if the container is + * not found, then return a response with a code 110 and a message "Container + * not found". Otherwise, return a response with a code 074 and a message + * "Container has been successfully removed". + * @return execution response + */ + public ResponseObject remove(int row) { + + int containerID = -1; + ResponseObject response = new ResponseObject(110, "Container not found"); + if(row < containers.size()) { + containerID = containers.get(row).getContainerID(); + for (Container container: containers) { + if (container.getContainerID() == containerID) { + containers.remove(container); + response = new ResponseObject(074, "Container has been successfully removed"); + break; + } + } + } + + return response; + + } + + /** + * This method returns the number of columns needed to construct a table of + * containers for GUI. It overrides a method from AbstractTableModel. + * @return number of columns + */ + @JsonIgnore + @Override + public int getColumnCount() { + return 7; + } + + /** + * This method returns the number rows needed to construct a table of + * containers for GUI by finding the size of containers array list. + * It overrides a method from AbstractTableModel. + * @return number of rows + */ + @JsonIgnore + @Override + public int getRowCount() { + return containers.size(); + } + + /** + * This method returns a listener list. This list is not required for anything, + * yet the method overrides a method from AbstractTableModel, which has to be + * ignored by JSON serialization process. Otherwise, the process will fail. + * @return listener list + */ + @JsonIgnore + @Override + public TableModelListener[] getTableModelListeners() { + return listenerList.getListeners(TableModelListener.class); + } + + /** + * This method takes a row index, and column index as parameters, and returns + * the value of a container attribute from containers. + * @return journey attribute values + */ + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + + Container particularContainer = containers.get(rowIndex); + + if (columnIndex == 0) { + return particularContainer.getContainerID(); + + } else if (columnIndex == 1) { + return particularContainer.getOwner(); + + } else if (columnIndex == 2) { + return particularContainer.getPosition(); + + } else if (columnIndex == 3) { + return particularContainer.getContentType(); + + } else if (columnIndex == 4) { + return particularContainer.getCompany(); + + } else if (columnIndex == 5) { + return particularContainer.isAvailability(); + + } else if (columnIndex == 6) { + return particularContainer.getCurrentJourney(); + + } else { + return null; + } + + } + + /** + * This method takes a column index as a parameter, and returns + * the name of a container attribute. + * @return container attribute names + */ + public String getColumnName(int columnIndex) { + + if (columnIndex == 0) { + return "Container ID"; + + } else if (columnIndex == 1) { + return "Current User"; + + } else if (columnIndex == 2) { + return "Position"; + + } else if (columnIndex == 3) { + return "Content Type"; + + } else if (columnIndex == 4) { + return "Company"; + + } else if (columnIndex == 5) { + return "Availability"; + + } else if (columnIndex == 6) { + return "Current Journey"; + + } else { + return null; + } + + } + +} diff --git a/System/src/main/java/management/HistoryBook.java b/System/src/main/java/management/HistoryBook.java new file mode 100644 index 0000000..6427a70 --- /dev/null +++ b/System/src/main/java/management/HistoryBook.java @@ -0,0 +1,95 @@ +package management; + +import java.util.ArrayList; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.time.Instant; +// A book keeping array lists of data history +public class HistoryBook { + + private ArrayList date; + private ArrayList temperature; + private ArrayList humidity; + private ArrayList pressure; + private ArrayList position; + + /** + * This constructor creates the array lists that keep track of data history + */ + public HistoryBook() { + super(); + date = new ArrayList(); + temperature = new ArrayList(); + humidity = new ArrayList(); + pressure = new ArrayList(); + position = new ArrayList(); + } + /** + * @param history + * This method and annotation fine tune the deserialization process + * it specifies how to get the data from database format + */ + @JsonCreator + @SuppressWarnings("unchecked") + public HistoryBook(Object[][] history) { + date = (ArrayList) history[0][0]; + temperature = (ArrayList) history[1][0]; + humidity = (ArrayList) history[2][0]; + pressure = (ArrayList) history[3][0]; + position = (ArrayList) history[4][0]; + } + /** + * This method and annotation specify how the object is going to be serialized + * it also creates a matrix with all the history data + * @return matrix of data history + */ + @JsonValue + public Object[][] show() { + Object table[][] = {{date},{temperature},{humidity},{pressure},{position}}; + return table; + } + + /** + * This method returns history of container + * it also creates a matrix with each column containing data regarding a certain variable + * this transposes the matrix that show() creates + * @return matrix of data history + */ + public Object[][] showTable() { + //Object table[][] = {{date},{temperature},{humidity},{pressure},{position}}; + int size = date.size(); + Object[][] table = new Object[size][5]; + + for (int i = 0; i < size; i++) { + + table[i][0] = date.get(i); + + table[i][1] = temperature.get(i); + table[i][2] = humidity.get(i); + table[i][3] = pressure.get(i); + table[i][4] = position.get(i); + + } + return table; +} + + /** + * @param date + * @param temperature + * @param humidity + * @param pressure + * @param position + * + * This method appends the new data to the arraylists for each measurement + */ + public void add(String date, int temperature, int humidity, int pressure, String position) { + this.date.add(date); + this.temperature.add(temperature); + this.humidity.add(humidity); + this.pressure.add(pressure); + this.position.add(position); + } + +} diff --git a/System/src/main/java/journeysManagement/Journey.java b/System/src/main/java/management/Journey.java similarity index 53% rename from System/src/main/java/journeysManagement/Journey.java rename to System/src/main/java/management/Journey.java index 9098546..c59d2b6 100644 --- a/System/src/main/java/journeysManagement/Journey.java +++ b/System/src/main/java/management/Journey.java @@ -1,92 +1,167 @@ -package journeysManagement; - -import java.security.SecureRandom; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; - - -public class Journey { - - private JourneyDatabase journeyDatabase; - private String journeyID; - private String origin; - private String destination; - private String departureDate; - private String arrivalDate; - - public Journey() { - - } - // @JsonCreator is used for deserializing - @JsonCreator - public Journey(String key) { - String[] info = key.split("[\",\\:\\{\\}\\s]+"); - this.journeyID = info[2]; - this.origin = info[4]; - this.destination = info[6]; - this.departureDate = info[8]; - this.arrivalDate = info[10]; - } - - public String getJourneyID() { - return journeyID; - } - // @JsonProperty() can be used to rename variables instead of overriding toString() - @JsonProperty("ID") - public void setJourneyID(String journeyID) { - this.journeyID = journeyID; - } - - public String getOrigin() { - return origin; - } - @JsonProperty("Origin") - public void setOrigin(String origin) { - this.origin = origin; - } - - public String getDestination() { - return destination; - } - @JsonProperty("Destination") - public void setDestination(String destination) { - this.destination = destination; - } - - public String getDepartureDate() { - return departureDate; - } - @JsonProperty("Departure") - public void setDepartureDate(String departureDate) { - this.departureDate = departureDate; - } - - public String getArrivalDate() { - return arrivalDate; - } - @JsonProperty("Arrival") - public void setArrivalDate(String arrivalDate) { - this.arrivalDate = arrivalDate; - } - - public String createJourneyID() { - - SecureRandom output = new SecureRandom(); - int cipher = output.nextInt(100000); - String journeyID = (String.format("%c%c", this.origin.charAt(0), this.destination.charAt(0)) + String.valueOf(cipher)); - if (this.journeyDatabase.getJourneys().containsKey(journeyID)) { - return createJourneyID(); - } - else - return this.journeyID = journeyID; - - } - - // @JsonValue is used for serializing - @JsonValue - public String toString() { - return "{" + "ID : " + journeyID + ", Origin : " + origin + ", Destination : " + destination + ", Departure : " + departureDate + ", Arrival : " + arrivalDate + "}"; - } -} +package management; + +import java.security.SecureRandom; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Journey class represent single marine journeys. + */ + +public class Journey { + + private String journeyID; + private String origin; + private String destination; + private String departureDate; + private String arrivalDate; + private JourneyDatabase journeyDatabase; + + /** + * This constructor is not used for anything. + */ + // Journey Constructor + public Journey() { + } + + /** + * This constructor initialises journey attributes after deserializing + * the journey database. It is necessary since jackson cannot deserialize + * a hash map composed of journey keys and container array lists, automatically. + */ + // @JsonCreator is used for deserializing + @JsonCreator + public Journey(String key) { + String[] info = key.split("[\",\\:\\{\\}\\s]+"); + this.journeyID = info[2]; + this.origin = info[4]; + this.destination = info[6]; + this.departureDate = info[8]; + this.arrivalDate = info[10]; + } + + /** + * This method returns the journey-ID + * @return journey-ID + */ + public String getJourneyID() { + return journeyID; + } + /** + * This method sets the journey-ID. + */ + // @JsonProperty() can be used to rename variables instead of overriding toString() + @JsonProperty("ID") + public void setJourneyID(String journeyID) { + this.journeyID = journeyID; + } + + /** + * This method returns the origin of the journey. + * @return origin + */ + public String getOrigin() { + return origin; + } + /** + * This method sets the origin of the journey. + */ + @JsonProperty("Origin") + public void setOrigin(String origin) { + this.origin = origin; + } + + /** + * This method returns the destination of the journey. + * @return destination + */ + public String getDestination() { + return destination; + } + /** + * This method sets the destination of the journey. + */ + @JsonProperty("Destination") + public void setDestination(String destination) { + this.destination = destination; + } + + /** + * This method returns the departure date of the journey. + * @return departure date + */ + public String getDepartureDate() { + return departureDate; + } + /** + * This method sets the departure date of the journey. + */ + @JsonProperty("Departure") + public void setDepartureDate(String departureDate) { + this.departureDate = departureDate; + } + + /** + * This method returns the arrival date of the journey. + * @return arrival date + */ + public String getArrivalDate() { + return arrivalDate; + } + /** + * This method sets the arrival date of the journey. + */ + @JsonProperty("Arrival") + public void setArrivalDate(String arrivalDate) { + this.arrivalDate = arrivalDate; + } + + /** + * This method returns the journey database. + * @return journey database + */ + public JourneyDatabase getJourneyDatabase() { + return journeyDatabase; + } + /** + * This method sets the journey database. + */ + public void setJourneyDatabase(JourneyDatabase database) { + this.journeyDatabase = database; + } + + /** + * This method creates a unique journey-ID of pattern XV00000, where X is the first + * letter of the origin site, and V is the first letter of the destination site, + * by generating a random code and recursively checking if there are any identical + * journey IDs in the journey database. If no identical journey-IDs were found, + * then set the generated journey-ID to the journey. + * @return journeyID + */ + public String createJourneyID() { + + SecureRandom output = new SecureRandom(); + int cipher = output.nextInt(100000); + String journeyID = (String.format("%c%c", this.origin.charAt(0), this.destination.charAt(0)) + String.valueOf(cipher)); + if (this.journeyDatabase.getJourneys().containsKey(journeyID)) { + return createJourneyID(); + } + else + return this.journeyID = journeyID; + + } + + /** + * This method returns a stringified format of a journey to be used when + * serializing to the container database. + * @return Journey information + */ + // @JsonValue is used for serializing + @JsonValue + public String toString() { + return "{" + "ID : " + journeyID + ", Origin : " + origin + ", Destination : " + destination + ", Departure : " + departureDate + ", Arrival : " + arrivalDate + "}"; + } + +} diff --git a/System/src/main/java/management/JourneyDatabase.java b/System/src/main/java/management/JourneyDatabase.java new file mode 100644 index 0000000..64c1d8f --- /dev/null +++ b/System/src/main/java/management/JourneyDatabase.java @@ -0,0 +1,528 @@ +package management; + +import java.util.Map; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import javax.swing.event.TableModelListener; +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import response.ResponseObject; +import serialization.JourneyDeserializer; +import serialization.JourneySerializer; + +/** + * JourneyDatabase class represent marine journeys that take in containers. + * It extends AbstractTableModel in order to change the format of the journey + * database, which is a hash map composed of journey keys and container array + * lists, into a table to be used for GUI. + */ + +public class JourneyDatabase extends AbstractTableModel { + + private static final long serialVersionUID = 2345990592978343022L; + + final String database = "journey_database.json"; + ObjectMapper mapper = new ObjectMapper(); + + /** + * Json annotations are used for instructing how to both serialize and + * deserialize. + */ + @JsonProperty("journeys") + @JsonSerialize(keyUsing = JourneySerializer.class) + @JsonDeserialize(keyUsing = JourneyDeserializer.class) + private Map> journeys; + + /** + * This constructor creates a hash map composed of journey keys and container + * array lists. This is necessary for deserializing. + */ + @JsonCreator + public JourneyDatabase() { + setJourneys(new HashMap>()); + } + + /** + * This method returns the journeys. + * @return journeys + */ + public Map> getJourneys() { + return journeys; + } + + /** + * This method sets the journeys. + */ + public void setJourneys(Map> journeys) { + this.journeys = journeys; + // Notify the view that the data has been changed + fireTableDataChanged(); + } + + /** + * This method produces a journey database as a JSON file with name + * "journey_database.json" to program's directory by serialising a newly + * created journey database object. + */ + public void produce() throws Exception { + mapper = new ObjectMapper(); + JourneyDatabase journeys = new JourneyDatabase(); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(journeys); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + + /** + * This method pulls the journey database from program's directory by + * deserializing "journey_database.json" file, and assigning the information + * to journeys. + */ + public void pull() throws Exception { + mapper = new ObjectMapper(); + this.journeys = mapper.readValue(new File(database), JourneyDatabase.class).getJourneys(); + } + + /** + * This method either produces or overwrites an existing journey database in + * program's directory with name "journey_database.json" by serialising + * journeys. + */ + public void push() throws Exception { + mapper = new ObjectMapper(); + String jsonResult = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); + Files.write(Paths.get(database), jsonResult.getBytes()); + } + + /** + * This method takes a journey as a parameter, and puts it together with an + * array list of containers to the current journeys. It also returns a response + * about the execution of the process. In case if the journey attributes are + * empty, then return a response with a code 210 and a message "Necessary parameters + * are not entered". Otherwise, return a response with a code 020 and a message + * "Journey has been created". + * @return execution response + */ + public ResponseObject create(Journey journey) { + + ResponseObject response; + ArrayList containerList; + + if(!((journey.getOrigin() == null) || (journey.getDestination() == null) || (journey.getDepartureDate() == null) || (journey.getArrivalDate() == null))){ + containerList = new ArrayList(); + getJourneys().put(journey, containerList); + // Codes from 000 to 100 indicate successful operation + response = new ResponseObject(020, "Journey has been created"); + } + + else { + // Codes from 100 to 999 indicate otherwise + response = new ResponseObject(210, "Necessary parameters are not entered"); + } + + return response; + + } + + /** + * This method takes a journey-ID, origin, destination, and array list of + * containers as parameters, and searches for a key with identical journey + * information. Once found, it adds those containers with position identical + * to the origin of the journey. It also returns a response about the execution + * of the process. In case if the array list of containers is empty, then + * return a response with a code 110 and a message "Container is not found". + * In case if the journey is not found, then return a response with a code + * 120 and a message "Journey is not found". Otherwise, return a response with + * a code 014 and a message "Container has been assigned to a journey" for every + * container that gets assigned. + * @return execution response + */ + public ResponseObject registerTo(String journeyID, String origin, String destination, ArrayList containerList) { + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + + if (containerList.size() == 0) { + response = new ResponseObject(110, "Container is not found"); + } + + else { + for (Journey key : journeys.keySet()) { + if (key.getJourneyID().equals(journeyID) && key.getOrigin().equals(origin) && key.getDestination().equals(destination)) { + for (Container container : containerList) { + if (container.getPosition().equals(key.getOrigin())) { + container.setCurrentJourney(journeyID); + journeys.get(key).add(container); + response = new ResponseObject(014, "Container has been assigned to a journey"); + } + } + } + } + } + + return response; + + } + + /** + * This method takes a client-ID as a parameter, and returns journeys with + * containers that currently belong to the client with the given client-ID. + * It searches every journey for containers that have an owner with the same + * given client-ID. Once found, these containers are then added to another array + * list of containers, which are then put to a hash map with the journey as the + * key and the containers as the value. This is repeated for every journey. + * @return journeys + */ + public Map> extract(int clientID) { + + Map> myJourneys = new HashMap>(); + + for (Journey key : journeys.keySet()) { + ArrayList myContainers = new ArrayList(); + for (Container container : journeys.get(key)) { + if (container.getOwner() == clientID) { + myContainers.add(container); + myJourneys.put(key, myContainers); + } + } + } + + return myJourneys; + + } + +// Unimplemented filter method, which was previously used, but currently relinquished. + +// // Generic Map filter, with predicate +// public Map filter(Map map, Predicate predicate) { +// return map.entrySet() +// .stream() +// .filter(x -> predicate.test(x.getValue())) +// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); +// } + + /** + * This method takes a criteria, and entry as parameters, and returns journeys + * with containers, that satisfy the criteria based on the entry. According to + * the given criteria, it searches for every journey that has a corresponding + * attribute equal to the entry. Once found, this journey together with their + * containers are then put to a hash map with the journey as the key and the + * containers as the value. This is repeated for every journey. + * @return journeys + */ + public Map> find(String criteria, String entry) { + + entry = StringUtils.lowerCase(entry); + + Map> myJourneys = new HashMap>(); + + if (criteria.equals("journeyID")) { + for (Journey key: this.journeys.keySet()) { + if (StringUtils.lowerCase(key.getJourneyID()).equals(entry)) { + myJourneys.put(key, this.journeys.get(key)); + } + } + } + + else if (criteria.equals("origin")) { + for (Journey key: this.journeys.keySet()) { + if (StringUtils.lowerCase(key.getOrigin()).equals(entry)) { + myJourneys.put(key, this.journeys.get(key)); + } + } + } + + else if (criteria.equals("destination")) { + for (Journey key: this.journeys.keySet()) { + if (StringUtils.lowerCase(key.getDestination()).equals(entry)) { + myJourneys.put(key, this.journeys.get(key)); + } + } + } + + else if (criteria.equals("departureDate")) { + for (Journey key: this.journeys.keySet()) { + if (StringUtils.lowerCase(key.getDepartureDate()).equals(entry)) { + myJourneys.put(key, this.journeys.get(key)); + } + } + } + + else if (criteria.equals("arrivalDate")) { + for (Journey key: this.journeys.keySet()) { + if (StringUtils.lowerCase(key.getArrivalDate()).equals(entry)) { + myJourneys.put(key, this.journeys.get(key)); + } + } + } + + return myJourneys; + + } + + /** + * This method takes a journey-ID, and position as parameters, and searches for + * a key with identical journey information. Once found, it updates the position + * of all journey containers to the given position. It also returns a response + * about the execution of the process. In case if the journey is not found, + * then return a response with a code 120 and a message "Journey is not found". + * In case if there were no containers for that journey, then return a response + * with a code 110 and a message "Container is not found". Otherwise, return a + * response with a code 070 and a message "Position has been updated" for every + * container that gets updated. + * @return execution response + */ + public ResponseObject updatePosition(String journeyID, String position) { + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + + for (Journey key : journeys.keySet()) { + if (key.getJourneyID().equals(journeyID)) { + response = new ResponseObject(110, "Container is not found"); + for (Container container : journeys.get(key)) { + container.setPosition(position); + response = new ResponseObject(070, "Position has been updated"); + } + } + } + + return response; + + } + + /** + * This method takes a journey-ID and date as parameters, and searches for a key + * with identical journey information. Once found, it updates the departure date + * of that particular journey to the given date. It also returns a response + * about the execution of the process. In case if the journey is not found, + * then return a response with a code 120 and a message "Journey is not found". + * Otherwise, return a response with a code 071 and a message "Departure date + * has been set". + * @return execution response + */ + public ResponseObject setDeparture(String journeyID, String date) { + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + + for (Journey key : journeys.keySet()) { + if (key.getJourneyID().equals(journeyID)) { + key.setDepartureDate(date); + response = new ResponseObject(071, "Departure date has been set"); + break; + } + } + + return response; + + } + + /** + * This method takes a journey-ID as a parameter, and searches for a + * key with identical journey information. Once found, it updates the arrival + * date of that particular journey to today's date, and sets the current journey + * of journey containers to "ARRIVED". It also returns a response about the + * execution of the process. In case if the journey is not found, then return + * a response with a code 120 and a message "Journey is not found". In case if + * there were no containers for that journey, then return a response with a code + * 110 and a message "Container is not found". Otherwise, return a response with + * a code 072 and a message "Arrival date has been set" for every container that + * gets updated. + * @return execution response + */ + public ResponseObject markArrived(String journeyID) { + + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/uuuu"); + LocalDate localDate = LocalDate.now(); + String date = dtf.format(localDate).toString(); + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + + for(Journey key : journeys.keySet()) { + if (key.getJourneyID().equals(journeyID)) { + key.setArrivalDate(date); + response = new ResponseObject(110, "Container is not found"); + for (Container container : journeys.get(key)) { + container.setCurrentJourney(journeyID + ": ARRIVED"); + response = new ResponseObject(072, "Arrival date has been set"); + } + } + } + + return response; + + } + + /** + * This method takes a journey-ID, and container-ID as parameters, and searches + * for a key with identical journey information. Once found, it searches for a + * container with the given container-ID, and removes it from that journey. It + * also returns a response about the execution of the process. In case if the + * journey is not found, then return a response with a code 120 and a message + * "Journey is not found". In case if the container is not found, then return + * a response with a code 110 and a message "Container is not found". Otherwise, + * return a response with a code 011 and a message "Container has been successfully + * removed". + * @return execution response + */ + public ResponseObject removeContainer(String journeyID, int containerID) { + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + + outerloop: + for (Journey journey : journeys.keySet()) { + if (journey.getJourneyID().equals(journeyID)) { + response = new ResponseObject(110, "Container is not found"); + for (Container container : journeys.get(journey)) { + if (container.getContainerID() == containerID) { + journeys.get(journey).remove(container); + response = new ResponseObject(011, "Container has been successfully removed"); + break outerloop; + } + } + } + } + + return response; + + } + + /** + * This method takes a journey-ID as a parameter, and searches for a key + * with identical journey information. Once found, it removes that particular + * journey from journeys. It also returns a response about the execution of + * the process. In case if the journey is not found, then return a response + * with a code 120 and a message "Journey is not found". Otherwise, return a + * response with a code 021 and a message "Journey has been completed and + * successfully removed". + * @return execution response + */ + public ResponseObject complete(String journeyID) { + + ResponseObject response = new ResponseObject(120, "Journey is not found"); + Iterator iterator = journeys.keySet().iterator(); + + while(iterator.hasNext()) { + Journey journey = iterator.next(); + if (journey.getJourneyID().equals(journeyID)) { + iterator.remove(); + response = new ResponseObject(021, "Journey has been completed and successfully removed"); + break; + } + } + + return response; + + } + + /** + * This method returns the number of columns needed to construct a table of + * journeys for GUI. It overrides a method from AbstractTableModel. + * @return number of columns + */ + @JsonIgnore + @Override + public int getColumnCount() { + return 5; + } + + /** + * This method returns the number rows needed to construct a table of + * journeys for GUI by finding the size of journeys map. It overrides + * a method from AbstractTableModel. + * @return number of rows + */ + @JsonIgnore + @Override + public int getRowCount() { + return journeys.size(); + } + + /** + * This method returns a listener list. This list is not required for anything, + * yet the method overrides a method from AbstractTableModel, which has to be + * ignored by JSON serialization process. Otherwise, the process will fail. + * @return listener list + */ + @JsonIgnore + @Override + public TableModelListener[] getTableModelListeners() { + return listenerList.getListeners(TableModelListener.class); + } + + /** + * This method takes a row index, and column index as parameters, and returns + * the value of a journey attribute from journeys. + * @return journey attribute values + */ + @Override + public String getValueAt(int rowIndex, int columnIndex) { + + ArrayList journeyKeyList = new ArrayList(journeys.keySet()); + + Journey perticularJourney = journeyKeyList.get(rowIndex); + + if (columnIndex == 0) { + return perticularJourney.getJourneyID(); + + } else if (columnIndex == 1) { + return perticularJourney.getOrigin(); + + } else if (columnIndex == 2) { + return perticularJourney.getDestination(); + + } else if (columnIndex == 3) { + return perticularJourney.getDepartureDate(); + + } else if (columnIndex == 4) { + return perticularJourney.getArrivalDate(); + + } else { + return null; + } + + } + + /** + * This method takes a column index as a parameter, and returns + * the name of a journey attribute. + * @return journey attribute names + */ + public String getColumnName(int columnIndex) { + + if (columnIndex == 0) { + return "Journey ID"; + + } else if (columnIndex == 1) { + return "Origin"; + + } else if (columnIndex == 2) { + return "Destination"; + + } else if (columnIndex == 3) { + return "Departure"; + + } else if (columnIndex == 4) { + return "Arrival"; + + } else { + return null; + } + + } + +} \ No newline at end of file diff --git a/System/src/main/java/management/LogisticsCompany.java b/System/src/main/java/management/LogisticsCompany.java new file mode 100644 index 0000000..8801aa7 --- /dev/null +++ b/System/src/main/java/management/LogisticsCompany.java @@ -0,0 +1,135 @@ +package management; + +import java.util.ArrayList; + +import response.ResponseObject; + +public class LogisticsCompany { + + + //This is to insure the company follows the singleton design pattern + private static LogisticsCompany instance; + //Company's attributes + private String name; + private int count ; + + private ClientDatabase clientDatabase; + private ContainerDatabase containerDatabase; + private JourneyDatabase journeyDatabase; + + //Constructor that pulls the latest changes from the json files. + public LogisticsCompany() { + + clientDatabase = new ClientDatabase(); + containerDatabase = new ContainerDatabase(); + journeyDatabase = new JourneyDatabase(); + + try { + clientDatabase.pull(); + containerDatabase.pull(); + journeyDatabase.pull(); + } catch (Exception e) { + e.printStackTrace(); + } + + count = clientDatabase.getClients().size() + 1 ; + + } + //This insures the uniqueness of client id + public void countIncrement() { + this.count++; + } + //Getters and setter + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public int getCount() { + return this.count; + } + + + public ClientDatabase getClientDatabase() { + return clientDatabase; + } + public void setClientDatabase(ClientDatabase clientDatabase) { + this.clientDatabase = clientDatabase; + } + + public ContainerDatabase getContainerDatabase() { + return containerDatabase; + } + public void setContainerDatabase(ContainerDatabase containerDatabase) { + this.containerDatabase = containerDatabase; + } + + public JourneyDatabase getJourneyDatabase() { + return journeyDatabase; + } + public void setJourneyDatabase(JourneyDatabase journeyDatabase) { + this.journeyDatabase = journeyDatabase; + } + + + //This method produces a fresh client Database. + public void cleanDataBase() { + + try { + clientDatabase.produce(); + } catch (Exception e) { + e.printStackTrace(); + } + this.count = 1; + + } + //This method is used by the company to create a client and add it to their database + //It returns a response Object corresponding to whether the creation is legal or not and gives the appropriate error codes and response for each of the cases. + public ResponseObject CreateNewClient(Client client) throws Exception { + + ResponseObject response; + + if (clientDatabase.legalPhoneNumberToAddClient(client) & clientDatabase.legalEmailToAddClient(client) & client.getfirstName() != null & client.getlastName() != null & client.getEmail() !=null & client.getPhoneNumber() != null) { + //reg.clients.add(client); + client.setId(count); + clientDatabase.getClients().add(client); + clientDatabase.push(); + countIncrement(); + + response = new ResponseObject(1000, "Client Added Successfully");; + + } else if (client.getfirstName() == null){ + response = new ResponseObject(1001, "Client Not Added. Missing name."); + + + } else if (client.getlastName() == null){ + response = new ResponseObject(1001, "Client Not Added. Missing name."); + + + } else if (client.getEmail() == null | client.getPhoneNumber() == null){ + response = new ResponseObject(1002, "Client Not Added. Missing contact information. Please provide an email or a phone number."); + + } else if (! clientDatabase.legalPhoneNumberToAddClient(client)){ + response = new ResponseObject(1003, "Client Not Added. Phone number already used by a different client"); + + } else { + response = new ResponseObject(1003, "Client Not Added. Email already used by a different client"); + + } + + return response; + + } + + + //This is to insure the the company follows a singleton design pattern + public static LogisticsCompany getInstance() { + if (instance == null) { + instance = new LogisticsCompany(); + } + return instance; + } + +} diff --git a/System/src/main/java/journeysManagement/ResponseObject.java b/System/src/main/java/response/ResponseObject.java similarity index 90% rename from System/src/main/java/journeysManagement/ResponseObject.java rename to System/src/main/java/response/ResponseObject.java index 28755e0..6168418 100644 --- a/System/src/main/java/journeysManagement/ResponseObject.java +++ b/System/src/main/java/response/ResponseObject.java @@ -1,10 +1,9 @@ -package journeysManagement; +package response; public class ResponseObject { private int errorCode; private String errorMessage; - // private String response; public ResponseObject(int errorCode, String errorMessage) { @@ -30,6 +29,4 @@ public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } - - } diff --git a/System/src/main/java/journeysManagement/JourneyDeserializer.java b/System/src/main/java/serialization/JourneyDeserializer.java similarity index 90% rename from System/src/main/java/journeysManagement/JourneyDeserializer.java rename to System/src/main/java/serialization/JourneyDeserializer.java index 1222a09..6af3b31 100644 --- a/System/src/main/java/journeysManagement/JourneyDeserializer.java +++ b/System/src/main/java/serialization/JourneyDeserializer.java @@ -1,18 +1,20 @@ -package journeysManagement; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.KeyDeserializer; - -public class JourneyDeserializer extends KeyDeserializer { - - @Override - public Journey deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { - //Use the string key here to return a real map key object - return new Journey(key); - } - - -} +package serialization; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.KeyDeserializer; + +import management.Journey; + +public class JourneyDeserializer extends KeyDeserializer { + + @Override + public Journey deserializeKey(String key, DeserializationContext ctxt) throws IOException, JsonProcessingException { + //Use the string key here to return a real map key object + return new Journey(key); + } + + +} diff --git a/System/src/main/java/journeysManagement/JourneySerializer.java b/System/src/main/java/serialization/JourneySerializer.java similarity index 93% rename from System/src/main/java/journeysManagement/JourneySerializer.java rename to System/src/main/java/serialization/JourneySerializer.java index a4b2d4a..5f0ebe3 100644 --- a/System/src/main/java/journeysManagement/JourneySerializer.java +++ b/System/src/main/java/serialization/JourneySerializer.java @@ -1,25 +1,27 @@ -package journeysManagement; - -import java.io.IOException; -import java.io.StringWriter; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializerProvider; - -public class JourneySerializer extends JsonSerializer { - - private ObjectMapper mapper = new ObjectMapper(); - - @Override - public void serialize(Journey value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException{ - - StringWriter writer = new StringWriter(); - mapper.writeValue(writer, value); - gen.writeFieldName(writer.toString()); - - } - -} +package serialization; + +import java.io.IOException; +import java.io.StringWriter; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; + +import management.Journey; + +public class JourneySerializer extends JsonSerializer { + + private ObjectMapper mapper = new ObjectMapper(); + + @Override + public void serialize(Journey value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException{ + + StringWriter writer = new StringWriter(); + mapper.writeValue(writer, value); + gen.writeFieldName(writer.toString()); + + } + +} diff --git a/System/src/main/java/utils/GridBagLayoutUtils.java b/System/src/main/java/utils/GridBagLayoutUtils.java new file mode 100644 index 0000000..f2f22b0 --- /dev/null +++ b/System/src/main/java/utils/GridBagLayoutUtils.java @@ -0,0 +1,15 @@ +package utils; + +import java.awt.GridBagConstraints; +import java.awt.Insets; + +public class GridBagLayoutUtils { + + public static GridBagConstraints constraint(int x, int y, int inset) { + GridBagConstraints c = new GridBagConstraints(); + c.gridx = x; + c.gridy = y; + c.insets = new Insets(inset, inset, inset, inset); + return c; + } +} diff --git a/System/src/main/java/view/AddHistoryView.java b/System/src/main/java/view/AddHistoryView.java new file mode 100644 index 0000000..0d1c7d1 --- /dev/null +++ b/System/src/main/java/view/AddHistoryView.java @@ -0,0 +1,104 @@ +package view; + +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.regex.Pattern; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import controller.AddHistorycontroller; +import controller.Session; + +public class AddHistoryView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private AddHistorycontroller addHistorycontroller; + private JLabel lblSession; + + public AddHistoryView(AddHistorycontroller controller) { + this.addHistorycontroller = controller; + initGUI(); + } + + /** + * this creates the GUI window that asks the company for container ID + * and the new measurement values to be updated for that container + * + */ + private void initGUI() { + //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Updating container information"); + setPreferredSize(new Dimension(800, 600)); + + // buttons( can add as many as you want :) ) + JPanel panel = new JPanel(); + + JTextField container = new JTextField(); + JLabel clabel = new JLabel("Container ID"); + + JTextField temperature = new JTextField(); + JLabel tlabel = new JLabel("Temperature"); + + JTextField humidity = new JTextField(); + JLabel hlabel = new JLabel("Humidity"); + + JTextField pressure = new JTextField(); + JLabel plabel = new JLabel("Pressure"); + +// JTextField position = new JTextField(); +// JLabel poslabel = new JLabel("Position"); + + JButton button = new JButton("Update info"); + + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/uuuu"); + LocalDate localDate = LocalDate.now(); + String date = dtf.format(localDate).toString(); + boolean idFormateChecker = container.getText().matches("-?\\d+"); + boolean TempFormatChecker = temperature.getText().matches("-?\\d+"); + boolean HumidFormatChecker = humidity.getText().matches("-?\\d+"); + boolean PressFormatChecker = pressure.getText().matches("-?\\d+"); + if (!idFormateChecker || !TempFormatChecker || !HumidFormatChecker || !PressFormatChecker) { + new IdFormatErrorGUI(); + } else { + addHistorycontroller.submitChanges(date,Integer.parseInt(container.getText()),Integer.parseInt(temperature.getText()),Integer.parseInt(humidity.getText()),Integer.parseInt(pressure.getText())); + } + } + }); + + panel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50)); + panel.setLayout(new GridLayout(7,2)); + panel.add(clabel); + panel.add(container); + panel.add(tlabel); + panel.add(temperature); + panel.add(hlabel); + panel.add(humidity); + panel.add(plabel); + panel.add(pressure); + panel.add(button); + add(panel); + + pack(); + + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + } + diff --git a/System/src/main/java/view/ClientPersonalInfoView.java b/System/src/main/java/view/ClientPersonalInfoView.java new file mode 100644 index 0000000..449941a --- /dev/null +++ b/System/src/main/java/view/ClientPersonalInfoView.java @@ -0,0 +1,115 @@ +package view; + +import java.awt.Dimension; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import controller.ClientPersonalInfoController; +import controller.Session; +import utils.GridBagLayoutUtils; + +public class ClientPersonalInfoView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private ClientPersonalInfoController controller; + private JLabel lblSession; + + + + + + public ClientPersonalInfoView(ClientPersonalInfoController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + + + setTitle("Account Details"); + setPreferredSize(new Dimension(800, 600)); + + + + + // toolbar + lblSession = new JLabel(); + + + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + setLayout(new GridBagLayout()); + + JTextField textFieldName = new JTextField(controller.getClient().getfirstName(), 20); + JTextField textFieldNameL = new JTextField(controller.getClient().getlastName(), 20); + JTextField textFieldDate = new JTextField(controller.getClient().getBirthDate(), 20); + JTextField textFieldEmail = new JTextField(controller.getClient().getEmail(), 20); + JTextField textFieldPhone = new JTextField(controller.getClient().getPhoneNumber(), 20); + + + JTextField txtPass = new JTextField(controller.getClient().getPassword(), 20); + JButton updateBtn = new JButton("Save Changes"); + + updateBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.updateInfo(textFieldName.getText(),textFieldNameL.getText(), textFieldDate.getText(), textFieldEmail.getText(), textFieldPhone.getText(), txtPass.getText()); + + } catch (Exception e1) { + e1.printStackTrace(); + } + } + }); + + add(new JLabel("Account details are listed below:"), GridBagLayoutUtils.constraint(0, 0, 5)); + + add(new JLabel("First Name:"), GridBagLayoutUtils.constraint(0, 1, 5)); + add(textFieldName, GridBagLayoutUtils.constraint(1, 1, 5)); + + add(new JLabel("Last Name:"), GridBagLayoutUtils.constraint(0, 2, 5)); + add(textFieldNameL, GridBagLayoutUtils.constraint(1, 2, 5)); + + add(new JLabel("Birth Date:"), GridBagLayoutUtils.constraint(0, 3, 5)); + add(textFieldDate, GridBagLayoutUtils.constraint(1, 3, 5)); + + add(new JLabel("Email:"), GridBagLayoutUtils.constraint(0, 4, 5)); + add(textFieldEmail, GridBagLayoutUtils.constraint(1, 4, 5)); + + add(new JLabel("Phone Number:"), GridBagLayoutUtils.constraint(0, 5, 5)); + add(textFieldPhone, GridBagLayoutUtils.constraint(1, 5, 5)); + + add(new JLabel("Password:"), GridBagLayoutUtils.constraint(0, 6, 5)); + add(txtPass, GridBagLayoutUtils.constraint(1, 6, 5)); + + + + add(updateBtn, GridBagLayoutUtils.constraint(1, 7, 5)); + + pack(); + setLocationRelativeTo(null); + + } + + + + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + + + public void showError(String errorMessage) { + JOptionPane.showMessageDialog(this, errorMessage, "Updating information", JOptionPane.INFORMATION_MESSAGE); + } +} + diff --git a/System/src/main/java/view/CompanyPersonalInfoView.java b/System/src/main/java/view/CompanyPersonalInfoView.java new file mode 100644 index 0000000..6d60c25 --- /dev/null +++ b/System/src/main/java/view/CompanyPersonalInfoView.java @@ -0,0 +1,120 @@ +package view; + + + import java.awt.Dimension; + import java.awt.GridBagLayout; + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; + + import javax.swing.JButton; + import javax.swing.JFrame; + import javax.swing.JLabel; + import javax.swing.JOptionPane; + import javax.swing.JTextField; + import javax.swing.SwingConstants; + + import controller.CompanyPersonalInfoController; + import controller.Session; + import utils.GridBagLayoutUtils; + + public class CompanyPersonalInfoView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private CompanyPersonalInfoController controller; + + private JLabel lblSession; + + + + + + public CompanyPersonalInfoView(CompanyPersonalInfoController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + + + //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Account Details"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + + + // toolbar + lblSession = new JLabel(); + + + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + setLayout(new GridBagLayout()); + + JTextField textFieldName = new JTextField(20); + JTextField textFieldNameL = new JTextField( 20); + JTextField textFieldDate = new JTextField(20); + JTextField textFieldEmail = new JTextField( 20); + JTextField textFieldPhone = new JTextField(20); + + + JTextField txtPass = new JTextField(20); + JButton updateBtn = new JButton("Save Changes"); + + updateBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.createInfo(textFieldName.getText(),textFieldNameL.getText(), textFieldDate.getText(), textFieldEmail.getText(), textFieldPhone.getText(), txtPass.getText()); + + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + add(new JLabel("Account details are listed below:"), GridBagLayoutUtils.constraint(0, 0, 5)); + + add(new JLabel("First Name:"), GridBagLayoutUtils.constraint(0, 1, 5)); + add(textFieldName, GridBagLayoutUtils.constraint(1, 1, 5)); + + add(new JLabel("Last Name:"), GridBagLayoutUtils.constraint(0, 2, 5)); + add(textFieldNameL, GridBagLayoutUtils.constraint(1, 2, 5)); + + add(new JLabel("Birth Date:"), GridBagLayoutUtils.constraint(0, 3, 5)); + add(textFieldDate, GridBagLayoutUtils.constraint(1, 3, 5)); + + add(new JLabel("Email:"), GridBagLayoutUtils.constraint(0, 4, 5)); + add(textFieldEmail, GridBagLayoutUtils.constraint(1, 4, 5)); + + add(new JLabel("Phone Number:"), GridBagLayoutUtils.constraint(0, 5, 5)); + add(textFieldPhone, GridBagLayoutUtils.constraint(1, 5, 5)); + + add(new JLabel("Password:"), GridBagLayoutUtils.constraint(0, 6, 5)); + add(txtPass, GridBagLayoutUtils.constraint(1, 6, 5)); + + + + add(updateBtn, GridBagLayoutUtils.constraint(1, 7, 5)); + + pack(); + setLocationRelativeTo(null); + + } + + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + + + public void showError(String errorMessage) { + JOptionPane.showMessageDialog(this, errorMessage, "Adding client", JOptionPane.INFORMATION_MESSAGE); + } + } + + + + diff --git a/System/src/main/java/view/ContainerErrorGUI.java b/System/src/main/java/view/ContainerErrorGUI.java new file mode 100644 index 0000000..9b57f0b --- /dev/null +++ b/System/src/main/java/view/ContainerErrorGUI.java @@ -0,0 +1,30 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.GridLayout; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class ContainerErrorGUI { + + /** + * this creates the pop up error when the container is not found + */ + public ContainerErrorGUI() { + JFrame frame = new JFrame(); + JPanel panel = new JPanel(); + JLabel errlabel = new JLabel("This container does not exist!"); + panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30)); + panel.setLayout(new GridLayout()); + panel.add(errlabel); + + frame.add(panel, BorderLayout.CENTER); + frame.setTitle("Error"); + frame.pack(); + frame.setVisible(true); + } + +} diff --git a/System/src/main/java/view/DateFormatErrorGUI.java b/System/src/main/java/view/DateFormatErrorGUI.java new file mode 100644 index 0000000..b0c40f3 --- /dev/null +++ b/System/src/main/java/view/DateFormatErrorGUI.java @@ -0,0 +1,29 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.GridLayout; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class DateFormatErrorGUI { + + /** + * this creates the pop up error when the entered date is in the wrong format + */ + public DateFormatErrorGUI() { + JFrame frame = new JFrame(); + JPanel panel = new JPanel(); + JLabel errlabel = new JLabel("The format for date is incorrect! Use this format: DD/MM/YYYY"); + panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100)); + panel.setLayout(new GridLayout()); + panel.add(errlabel); + + frame.add(panel, BorderLayout.CENTER); + frame.setTitle("Error"); + frame.pack(); + frame.setVisible(true); + } +} diff --git a/System/src/main/java/view/DisplayClientsView.java b/System/src/main/java/view/DisplayClientsView.java new file mode 100644 index 0000000..ed07d07 --- /dev/null +++ b/System/src/main/java/view/DisplayClientsView.java @@ -0,0 +1,101 @@ + +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayClientsController; + +public class DisplayClientsView extends JFrame { + + private static final long serialVersionUID = 2888791217183873215L; + private DisplayClientsController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayClientsView(DisplayClientsController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("Clients"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.filter(); + } + }); + + + + + JButton btnAddClient = new JButton("Add Client"); + + btnAddClient.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.addClient(); + + } + }); + + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnAddClient); + toolbar.add(btnRefresh); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + +} \ No newline at end of file diff --git a/System/src/main/java/view/DisplayContainersView.java b/System/src/main/java/view/DisplayContainersView.java new file mode 100644 index 0000000..e6674e3 --- /dev/null +++ b/System/src/main/java/view/DisplayContainersView.java @@ -0,0 +1,134 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayContainersController; + +public class DisplayContainersView extends JFrame { + + private static final long serialVersionUID = 4212860552112409964L; + private DisplayContainersController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayContainersView(DisplayContainersController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("Containers"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnFindAvailable = new JButton("Show available containers"); + btnFindAvailable.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.findAvailable();; + } + }); + + JButton btnAdd = new JButton("Register new"); + btnAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.register(); + } + }); + + JButton btnDelete = new JButton("Remove"); // add code to delete from database so changes are not lost upon exit + btnDelete.setEnabled(false); + btnDelete.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.delete(tblInventory.getSelectedRow()); + } + }); + + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + JButton btnSave = new JButton("Permanently save changes"); + btnSave.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.save(); + System.out.print("Saved"); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnFindAvailable); + toolbar.add(btnAdd); + toolbar.add(btnDelete); + toolbar.add(btnRefresh); + toolbar.add(btnSave); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnDelete.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + +} diff --git a/System/src/main/java/view/DisplayJourneyContainersClientView.java b/System/src/main/java/view/DisplayJourneyContainersClientView.java new file mode 100644 index 0000000..5517e2a --- /dev/null +++ b/System/src/main/java/view/DisplayJourneyContainersClientView.java @@ -0,0 +1,103 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayContainersController; +import controller.DisplayJourneyContainersClientController; + +public class DisplayJourneyContainersClientView extends JFrame { + + private static final long serialVersionUID = 4212860552112409964L; + private DisplayJourneyContainersClientController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayJourneyContainersClientView(DisplayJourneyContainersClientController displayContainersController) { + this.controller = displayContainersController; + initGUI(); + } + + private void initGUI() { + setTitle("Containers"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnSee = new JButton("History"); + btnSee.setEnabled(false); + btnSee.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.showHistory(tblInventory.getSelectedRow()); + } + }); + + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnRefresh); + toolbar.add(btnSee); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnSee.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + +} diff --git a/System/src/main/java/view/DisplayJourneyContainersCompanyView.java b/System/src/main/java/view/DisplayJourneyContainersCompanyView.java new file mode 100644 index 0000000..08dbd6d --- /dev/null +++ b/System/src/main/java/view/DisplayJourneyContainersCompanyView.java @@ -0,0 +1,101 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayJourneyContainersCompanyController; + +public class DisplayJourneyContainersCompanyView extends JFrame { + + private static final long serialVersionUID = -5189631801554166475L; + private DisplayJourneyContainersCompanyController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayJourneyContainersCompanyView(DisplayJourneyContainersCompanyController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("Containers"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnRemove = new JButton("Remove from journey"); + btnRemove.setEnabled(false); + btnRemove.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.remove(tblInventory.getSelectedRow()); + } + }); + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnRemove); + toolbar.add(btnRefresh); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnRemove.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + +} diff --git a/System/src/main/java/view/DisplayJourneysClientView.java b/System/src/main/java/view/DisplayJourneysClientView.java new file mode 100644 index 0000000..2e31ef5 --- /dev/null +++ b/System/src/main/java/view/DisplayJourneysClientView.java @@ -0,0 +1,102 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayJourneysCompanyController; +import controller.DisplayJourneysClientController; + +public class DisplayJourneysClientView extends JFrame { + + private static final long serialVersionUID = 4212860552112409964L; + private DisplayJourneysClientController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayJourneysClientView(DisplayJourneysClientController displayJourneysController) { + this.controller = displayJourneysController; + initGUI(); + } + private void initGUI() { + setTitle("Journeys"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnShowContainers = new JButton("Show my containers"); + btnShowContainers.setEnabled(false); + btnShowContainers.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.showContainers(tblInventory.getSelectedRow()); + } + }); + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnShowContainers); + toolbar.add(btnRefresh); +// toolbar.add(btnSave); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnShowContainers.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + +} diff --git a/System/src/main/java/view/DisplayJourneysCompanyView.java b/System/src/main/java/view/DisplayJourneysCompanyView.java new file mode 100644 index 0000000..3ec8a55 --- /dev/null +++ b/System/src/main/java/view/DisplayJourneysCompanyView.java @@ -0,0 +1,180 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayJourneysCompanyController; + +public class DisplayJourneysCompanyView extends JFrame { + + private static final long serialVersionUID = 4212860552112409964L; + private DisplayJourneysCompanyController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayJourneysCompanyView(DisplayJourneysCompanyController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("Journeys"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnShowContainers = new JButton("Show containers"); + btnShowContainers.setEnabled(false); + btnShowContainers.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.showContainers(tblInventory.getSelectedRow()); + } + }); + + JButton btnPosition = new JButton("Update position"); + btnPosition.setEnabled(false); + btnPosition.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.updatePosition(tblInventory.getSelectedRow()); + } + }); + + JButton btnDepart = new JButton("Set departure date"); + btnDepart.setEnabled(false); + btnDepart.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.setDeparture(tblInventory.getSelectedRow()); + } + }); + + JButton btnArrived = new JButton("Set arrival to today"); + btnArrived.setEnabled(false); + btnArrived.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.arrived(tblInventory.getSelectedRow()); + } + }); + + JButton btnAdd = new JButton("Add new journey"); + btnAdd.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.add(); + } + }); + + JButton btnDelete = new JButton("Complete and Remove"); + btnDelete.setEnabled(false); + btnDelete.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.delete(tblInventory.getSelectedRow()); + } + }); + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + JButton btnSave = new JButton("Permanently save changes"); + btnSave.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.save(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnShowContainers); + toolbar.add(btnPosition); + toolbar.add(btnDepart); + toolbar.add(btnArrived); + toolbar.add(btnAdd); + toolbar.add(btnDelete); + toolbar.add(btnRefresh); + toolbar.add(btnSave); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnShowContainers.setEnabled((tblInventory.getSelectedRow() >= 0)); + btnPosition.setEnabled((tblInventory.getSelectedRow() >= 0)); + btnDepart.setEnabled((tblInventory.getSelectedRow() >= 0)); + btnArrived.setEnabled((tblInventory.getSelectedRow() >= 0)); + btnDelete.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + public void showError() { + JOptionPane.showMessageDialog(this, "Both origin and destination are required to create a new journey.", "Neccessary parameters are not entered.", JOptionPane.ERROR_MESSAGE); + } + + public void showError2() { + JOptionPane.showMessageDialog(this, "Text field cannot be left empty", "Position unchanged", JOptionPane.ERROR_MESSAGE); + } + + public void showError3() { + JOptionPane.showMessageDialog(this, "Date should be of the format DD/MM/YYYY", "Incorrect date format", JOptionPane.ERROR_MESSAGE); + } + +} diff --git a/System/src/main/java/view/DisplayJourneysRegisterView.java b/System/src/main/java/view/DisplayJourneysRegisterView.java new file mode 100644 index 0000000..3035ed2 --- /dev/null +++ b/System/src/main/java/view/DisplayJourneysRegisterView.java @@ -0,0 +1,111 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.DisplayJourneysRegisterController; + +public class DisplayJourneysRegisterView extends JFrame { + + private static final long serialVersionUID = 4212860552112409994L; + private DisplayJourneysRegisterController controller; + private JTable tblInventory; + private JLabel lblSession; + + public DisplayJourneysRegisterView(DisplayJourneysRegisterController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("Journeys"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFind = new JButton("Find"); + btnFind.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.find(); + } + }); + + JButton btnRefresh = new JButton("Refresh"); + btnRefresh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.refresh(); + } + }); + + JButton btnSelect = new JButton("Select journey"); + btnSelect.setEnabled(false); + btnSelect.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + controller.select(tblInventory.getSelectedRow()); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFind); + toolbar.add(btnRefresh); + toolbar.add(btnSelect); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnSelect.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + public void showConfirmation(String message) { + JOptionPane.showMessageDialog(this, message, "Confirmation", JOptionPane.INFORMATION_MESSAGE); + } + +} diff --git a/System/src/main/java/view/DisplayRegisterView.java b/System/src/main/java/view/DisplayRegisterView.java new file mode 100644 index 0000000..4a91010 --- /dev/null +++ b/System/src/main/java/view/DisplayRegisterView.java @@ -0,0 +1,135 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.SwingConstants; +import javax.swing.border.Border; + +import controller.DisplayRegisterController; +import controller.Session; + +public class DisplayRegisterView extends JFrame { + + private static final long serialVersionUID = 4212863552112409964L; + private DisplayRegisterController controller; + private JLabel lblSession; + private JPanel boxFromTo = new JPanel(new GridLayout(2, 2, 2, 0)); + private JPanel boxCompany = new JPanel(new GridLayout(2, 1, 0, 0)); + private JPanel boxContainers = new JPanel(new GridLayout(2, 2, 2, 0)); + private JPanel panel = new JPanel(); + + public DisplayRegisterView(DisplayRegisterController displayRegisterController) { + this.controller = displayRegisterController; + initGUI(); + } + + private void initGUI() { + setTitle("Register"); + setPreferredSize(new Dimension(800, 600)); + + panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + + JTextField origin = new JTextField(); + JTextField destination = new JTextField(); + JTextField company = new JTextField(); + JTextField contentType = new JTextField(); + JTextField numberOfContainers = new JTextField(); + + String[] labelStrings = { + "From: ", + "To: ", + "Company: ", + "Content Type: ", + "Number of Containers: " + }; + JLabel[] labels = new JLabel[labelStrings.length]; + for (int i = 0; i < labelStrings.length; i++) { + labels[i] = new JLabel(labelStrings[i], + JLabel.LEFT); + labels[i].setFont(new java.awt.Font("Century Gothic", Font.PLAIN, 16)); + } + + Border grayline = BorderFactory.createLineBorder(Color.gray); + + boxFromTo.add(labels[0]); boxFromTo.add(labels[1]); + boxFromTo.add(origin); boxFromTo.add(destination); + boxFromTo.setBorder(grayline); + + boxCompany.add(labels[2]); + boxCompany.add(company); + boxCompany.setBorder(grayline); + + boxContainers.add(labels[3]); boxContainers.add(labels[4]); + boxContainers.add(contentType); boxContainers.add(numberOfContainers); + boxContainers.setBorder(grayline); + + JLabel title = new JLabel("Booking Information: ", JLabel.LEFT); + title.setFont(new java.awt.Font("Century Gothic", Font.PLAIN, 16)); + + panel.add(title); + + JPanel[] boxes = {boxFromTo, boxCompany, boxContainers}; + for (JPanel box : boxes) { + panel.add(box); + panel.add(Box.createRigidArea(new Dimension(0, 20))); + } + + JPanel leftHalf = new JPanel() { + //Don't allow us to stretch vertically. + public Dimension getMaximumSize() { + Dimension pref = getPreferredSize(); + return new Dimension(Integer.MAX_VALUE, + pref.height); + } + }; + + leftHalf.add(panel); + add(leftHalf, BorderLayout.CENTER); + + // buttons + JButton btnContinue = new JButton("Continue"); + btnContinue.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.request(origin.getText(), destination.getText(), company.getText(), contentType.getText(), numberOfContainers.getText()); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnContinue); + toolbar.add(Box.createHorizontalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + pack(); + setLocationRelativeTo(null); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + public void showError(String errorMessage) { + JOptionPane.showMessageDialog(this, errorMessage, "Input error", JOptionPane.ERROR_MESSAGE); + } + +} diff --git a/System/src/main/java/view/FriendsMainMenuView.java b/System/src/main/java/view/FriendsMainMenuView.java new file mode 100644 index 0000000..7a2b8c4 --- /dev/null +++ b/System/src/main/java/view/FriendsMainMenuView.java @@ -0,0 +1,97 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JToolBar; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.TableModel; + +import controller.Session; +import controller.FriendsMainMenuController; + +public class FriendsMainMenuView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private FriendsMainMenuController controller; + private JTable tblInventory; + private JLabel lblSession; + + public FriendsMainMenuView(FriendsMainMenuController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setTitle("User Manager"); + setPreferredSize(new Dimension(800, 600)); + + // buttons + JButton btnFriend = new JButton("Share my information with a friend"); + btnFriend.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.friendAdding(); + } + }); + + JButton btnShowJourneys = new JButton("Show friend's journeys"); + btnShowJourneys.setEnabled(false); + btnShowJourneys.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.showJourneys(tblInventory.getSelectedRow()); + } + }); + // toolbar + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + + JToolBar toolbar = new JToolBar(); + toolbar.add(btnFriend); + toolbar.add(btnShowJourneys); + + toolbar.add(Box.createHorizontalGlue()); + + toolbar.add(lblSession); + add(toolbar, BorderLayout.NORTH); + + // table + tblInventory = new JTable(); + tblInventory.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + tblInventory.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + btnShowJourneys.setEnabled((tblInventory.getSelectedRow() >= 0)); + } + }); + add(new JScrollPane(tblInventory), BorderLayout.CENTER); + + pack(); + setLocationRelativeTo(null); + } + + public void setTableModel(TableModel model) { + tblInventory.setModel(model); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + public void showError(String errorMessage) { + JOptionPane.showMessageDialog(this, errorMessage, "Adding Friend", JOptionPane.INFORMATION_MESSAGE); + } +} \ No newline at end of file diff --git a/System/src/main/java/view/HistoryView.java b/System/src/main/java/view/HistoryView.java new file mode 100644 index 0000000..45bfe60 --- /dev/null +++ b/System/src/main/java/view/HistoryView.java @@ -0,0 +1,89 @@ +package view; + +import java.awt.Dimension; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; + +import controller.HistoryController; + +public class HistoryView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private HistoryController historyController; + //private JLabel lblSession; + + + + public HistoryView(HistoryController controller) { + + this.historyController = controller; + initGUI(); + } + + + + /** + * this is the GUI window that shows the table of container history + * uses the matrix that its controller generates + * + */ + private void initGUI() { + + + String[] columns = new String[] { + "date", "temperature", "humidity", "pressure", "position" + }; + + Object[][] data = historyController.history(); + + + if (data == null) { + //System.out.print("sdgiuoanbh"); + new IdFormatErrorGUI(); + } else { + //System.out.print("WOOOORKS"); + //create table with data + JTable table = new JTable(data, columns); + + //add the table to the frame + add(new JScrollPane(table)); + + //this.setTitle("Table"); + //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setVisible(true); + + + setTitle("History Table"); + setPreferredSize(new Dimension(800, 600)); + + + //JPanel panel = new JPanel(); + + //panel.add(table); + //add(panel); + + pack(); + + } + + + + + + + } + + + //public void setSession(Session sessionModel) { + //lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + //} + + + + + +} diff --git a/System/src/main/java/view/IdFormatErrorGUI.java b/System/src/main/java/view/IdFormatErrorGUI.java new file mode 100644 index 0000000..7c8b580 --- /dev/null +++ b/System/src/main/java/view/IdFormatErrorGUI.java @@ -0,0 +1,31 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.GridLayout; + +import javax.swing.BorderFactory; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class IdFormatErrorGUI { + + /** + * this creates the pop up error when wrong formats or types have been entered for either + * temperature, humidity, pressure or container ID + */ + public IdFormatErrorGUI() { + JFrame frame = new JFrame(); + JPanel panel = new JPanel(); + JLabel errlabel = new JLabel("Please enter Integers for Container ID, Temperature, Humidty and Pressure"); + panel.setBorder(BorderFactory.createEmptyBorder(100, 100, 100, 100)); + panel.setLayout(new GridLayout()); + panel.add(errlabel); + + frame.add(panel, BorderLayout.CENTER); + frame.setTitle("Error"); + frame.pack(); + frame.setVisible(true); + } + +} diff --git a/System/src/main/java/view/LoginView.java b/System/src/main/java/view/LoginView.java new file mode 100644 index 0000000..b986b68 --- /dev/null +++ b/System/src/main/java/view/LoginView.java @@ -0,0 +1,60 @@ +package view; + +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPasswordField; +import javax.swing.JTextField; + +import controller.LoginController; +import utils.GridBagLayoutUtils; + +public class LoginView extends JFrame { + + private static final long serialVersionUID = 8981053836072595592L; + + private JButton btnLogin; + private JTextField txtLogin; + private JPasswordField txtPass; + private LoginController controller; + + public LoginView(LoginController controller) { + this.controller = controller; + initGUI(); + } + + private void initGUI() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setResizable(false); + setTitle("Login"); + setLayout(new GridBagLayout()); + + txtLogin = new JTextField(15); + txtPass = new JPasswordField(15); + btnLogin = new JButton("Login"); + btnLogin.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + controller.validateCredentials(txtLogin.getText(), String.valueOf(txtPass.getPassword())); + } + }); + + add(new JLabel("Username:"), GridBagLayoutUtils.constraint(0, 0, 5)); + add(txtLogin, GridBagLayoutUtils.constraint(1, 0, 5)); + add(new JLabel("Password:"), GridBagLayoutUtils.constraint(0, 1, 5)); + add(txtPass, GridBagLayoutUtils.constraint(1, 1, 5)); + add(btnLogin, GridBagLayoutUtils.constraint(1, 2, 5)); + + pack(); + setLocationRelativeTo(null); + } + + public void showError() { + JOptionPane.showMessageDialog(this, "Wrong username/password combination", "Login error", JOptionPane.ERROR_MESSAGE); + } +} diff --git a/System/src/main/java/view/MainMenuClientView.java b/System/src/main/java/view/MainMenuClientView.java new file mode 100644 index 0000000..52a8130 --- /dev/null +++ b/System/src/main/java/view/MainMenuClientView.java @@ -0,0 +1,116 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Paths; + +import javax.swing.Box; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import javax.swing.JToolBar; +import javax.swing.SwingConstants; + +import controller.MainMenuClientController; +import controller.Session; + + +public class MainMenuClientView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private MainMenuClientController MainMenucontroller; + private JLabel lblSession; + private JLabel imageLabel; + private JPanel box = new JPanel(new GridLayout(4, 1, 0, 10)); + + public MainMenuClientView(MainMenuClientController controller) { + this.MainMenucontroller = controller; + initGUI(); + } + + + private void initGUI() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Main Menu"); + setPreferredSize(new Dimension(920, 630)); + setResizable(false); + + try { + imageLabel = new JLabel(); +// URL url = this.getClass().getResource("/resources/cargo_blue.gif"); + URL url = Paths.get("cargo_blue.gif").toUri().toURL(); + ImageIcon imageIcon = new ImageIcon(url); + imageLabel.setIcon(imageIcon); + add(imageLabel, BorderLayout.CENTER); + } + catch (NullPointerException | MalformedURLException e) { + + } + + // buttons( can add as many as you want :) ) + + JButton btnClient = new JButton("Info"); + box.add(btnClient); + btnClient.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.updateInfo(); + } + }); + + JButton btnFriend = new JButton("See/Add Friends"); + box.add(btnFriend); + btnFriend.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.friend(); + } + }); + + JButton btnJourney = new JButton("My journeys"); + box.add(btnJourney); + btnJourney.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displayJourneys(); + } + }); + + JButton btnRegister = new JButton("Register container(s) for journeys"); + box.add(btnRegister); + btnRegister.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.register(); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setVerticalAlignment(SwingConstants.BOTTOM); + + JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); + toolbar.addSeparator(new Dimension(10, 10)); + toolbar.add(box); + toolbar.add(Box.createVerticalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.WEST); + pack(); + setLocationRelativeTo(null); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + } + + + diff --git a/System/src/main/java/view/MainMenuCompanyView.java b/System/src/main/java/view/MainMenuCompanyView.java new file mode 100644 index 0000000..9920944 --- /dev/null +++ b/System/src/main/java/view/MainMenuCompanyView.java @@ -0,0 +1,120 @@ +package view; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Paths; + +import javax.swing.Box; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JToolBar; +import javax.swing.SwingConstants; + +import controller.MainMenuCompanyController; +import controller.Session; + +public class MainMenuCompanyView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private MainMenuCompanyController MainMenucontroller; + private JLabel lblSession; + private JLabel imageLabel; + private JPanel box = new JPanel(new GridLayout(7, 1, 0, 10)); + + public MainMenuCompanyView(MainMenuCompanyController controller) { + this.MainMenucontroller = controller; + initGUI(); + } + + private void initGUI() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Main Menu"); + setPreferredSize(new Dimension(920, 630)); + setResizable(false); + + try { + imageLabel = new JLabel(); +// URL url = this.getClass().getResource("/resources/cargo_blue.gif"); + URL url = Paths.get("cargo_blue.gif").toUri().toURL(); + ImageIcon imageIcon = new ImageIcon(url); + imageLabel.setIcon(imageIcon); + add(imageLabel, BorderLayout.CENTER); + } + catch (NullPointerException | MalformedURLException e) { + + } + + // buttons + + JButton btnClient = new JButton("Clients"); + box.add(btnClient); + btnClient.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displayClients(); + } + }); + + JButton btnContainer = new JButton("Containers"); + box.add(btnContainer); + btnContainer.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displayContainers(); + } + }); + + JButton btnJourney = new JButton("Journeys"); + box.add(btnJourney); + btnJourney.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displayJourneys(); + } + }); + JButton btnContainerUpdate = new JButton("Update container Status"); + box.add(btnContainerUpdate); + btnContainerUpdate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displayAddHistory(); + } + }); + JButton btnContainerInfo = new JButton("See Container History"); + box.add(btnContainerInfo); + btnContainerInfo.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainMenucontroller.displaySeeHistory(); + } + }); + + // toolbar + lblSession = new JLabel(); + lblSession.setVerticalAlignment(SwingConstants.BOTTOM); + JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); + toolbar.addSeparator(new Dimension(10, 10)); + toolbar.add(box); + toolbar.add(Box.createVerticalGlue()); + toolbar.add(lblSession); + add(toolbar, BorderLayout.WEST); + pack(); + setLocationRelativeTo(null); + } + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + } + + + diff --git a/System/src/main/java/view/SeeHistoryView.java b/System/src/main/java/view/SeeHistoryView.java new file mode 100644 index 0000000..5aa1b23 --- /dev/null +++ b/System/src/main/java/view/SeeHistoryView.java @@ -0,0 +1,91 @@ +package view; + +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.regex.Pattern; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import controller.SeeHistoryController; +import controller.Session; + +public class SeeHistoryView extends JFrame { + + private static final long serialVersionUID = 989075282041187452L; + private SeeHistoryController seeHistoryController; + private JLabel lblSession; + + + + public SeeHistoryView(SeeHistoryController controller) { + this.seeHistoryController = controller; + initGUI(); + } + + + + /** + * this creates the GUI window which asks for the container ID and shows the container's history + */ + private void initGUI() { + + setTitle("Choosing Container"); + setPreferredSize(new Dimension(800, 600)); + + JPanel panel = new JPanel(); + JTextField container = new JTextField(); + JLabel label = new JLabel("Container ID"); + + + JButton button = new JButton("See info"); + + lblSession = new JLabel(); + lblSession.setHorizontalAlignment(SwingConstants.RIGHT); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + boolean idFormateChecker = container.getText().matches("-?\\d+"); + + if (!idFormateChecker) { + new IdFormatErrorGUI(); + } else { + + seeHistoryController.showHistory(Integer.parseInt(container.getText())); + + } + + + } + }); + + + panel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50)); + panel.setLayout(new GridLayout(7,2)); + + + panel.add(label); + panel.add(container); + panel.add(button); + add(panel); + + pack(); + + + } + + + public void setSession(Session sessionModel) { + lblSession.setText("" + sessionModel.getUsername() + " (" + sessionModel.getRole() + ")"); + } + + +} diff --git a/System/src/main/resources/AddingInformation.feature b/System/src/main/resources/AddingInformation.feature new file mode 100644 index 0000000..5420daa --- /dev/null +++ b/System/src/main/resources/AddingInformation.feature @@ -0,0 +1,39 @@ +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Adding information to containers + + + @tag1 + Scenario: Successful addition of info + Given a container with id 100 + And a logisitc company "Maersk" + When logisitc company chooses the container with journey id 100 + And add Temperature 101 + And add Humidity 102 + And add Pressure 103 + And add Position "Copenhagen" + Then update container's values + + @tag2 + Scenario: adding info to a non-existent container + Given a logisitc company "Maersk" + And a container with id 100 + When logisitc company chooses the container with journey id 200 + Then show message: container does not exist \ No newline at end of file diff --git a/System/src/main/resources/BookContainer.feature b/System/src/main/resources/BookContainer.feature new file mode 100644 index 0000000..6c7224f --- /dev/null +++ b/System/src/main/resources/BookContainer.feature @@ -0,0 +1,76 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Booking containers + + @tag1 + Scenario: Book containers + Given location "Copenhagen" + And content-type "Fish" + And company "Maersk" + And number of containers 5 + And shipping yard in "Copenhagen" with 20 containers + When booking + Then confirm booking "Container has been registered" 010 + + @tag2 + Scenario: Book fewer containers than requested + Given location "Copenhagen" + And content-type "Fish" + And company "Maersk" + And number of containers 5 + And shipping yard in "Copenhagen" with 3 containers + When booking + Then confirm booking "Container has been registered" 010 + + @tag3 + Scenario: Deny booking due to unavailable containers + Given location "Copenhagen" + And content-type "Fish" + And company "Maersk" + And number of containers 5 + When booking + Then deny booking "Container is not found" 110 + + @tag4 + Scenario: Deny booking due to missing content type + Given location "Copenhagen" + And company "Maersk" + And number of containers 5 + And shipping yard in "Copenhagen" with 20 containers + When booking + Then deny booking "Necessary parameters are not entered" 210 + + @tag5 + Scenario: Deny booking due to missing company + Given location "Copenhagen" + And content-type "Fish" + And number of containers 5 + And shipping yard in "Copenhagen" with 20 containers + When booking + Then deny booking "Necessary parameters are not entered" 210 + + @tag6 + Scenario: Deny booking due to missing company and content-type + Given location "Copenhagen" + And number of containers 5 + And shipping yard in "Copenhagen" with 20 containers + When booking + Then deny booking "Necessary parameters are not entered" 210 + \ No newline at end of file diff --git a/System/src/main/resources/ClientUpdate.feature b/System/src/main/resources/ClientUpdate.feature index f5e7c70..53a102f 100644 --- a/System/src/main/resources/ClientUpdate.feature +++ b/System/src/main/resources/ClientUpdate.feature @@ -1,49 +1,49 @@ -#Author: your.email@your.domain.com -#Keywords Summary : -#Feature: List of scenarios. -#Scenario: Business rule through list of steps with arguments. -#Given: Some precondition step -#When: Some key actions -#Then: To observe outcomes or validation -#And,But: To enumerate more Given,When,Then steps -#Scenario Outline: List of steps for data-driven as an Examples and -#Examples: Container for s table -#Background: List of steps run before each of the scenarios -#""" (Doc Strings) -#| (Data Tables) -#@ (Tags/Labels):To group Scenarios -#<> (placeholder) -#"" -## (Comments) -#Sample Feature Definition Template -@tag -Feature: Update information - I want to use this template for my feature file - - @tag1 - Scenario: Successfull update of al information except name and birth date - Given registered client - When the client wants to update all their information except their name and birth date - Then the informtion is updated successfully - - Scenario: Unsuccessfull update - Given unregistered client - When the person wants to update all their information except their name and birth date - Then the informtion is not updated successfully - - Scenario: Unsuccessfull update 2 - Given registered client - And a phone number that exists in the system - When the client wants to update all their contact phone number to already existing phone number - Then the informtion is not updated - - - Scenario: Unsuccessfull update 3 - Given registered client - And a email that exists in the system - When the client wants to update all their contact phone number to already existing email - Then the informtion is not updated version 2 - - - - +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Update information + Client wants to update their personal information. + + @tag1 + Scenario: Successfull update of al information except name and birth date + Given registered client + When the client wants to update all their information except their name and birth date + Then the informtion is updated successfully + + Scenario: UnSuccessful update due to the client not being registered by the company + Given unregistered client + When the person wants to update all their information except their name and birth date + Then the informtion is not updated successfully + + Scenario: UnSuccessful update due to illegal phone number + Given registered client + And a phone number that exists in the system + When the client wants to update all their contact phone number to already existing phone number + Then the informtion is not updated + + + Scenario: UnSuccessful update due to illegal email + Given registered client + And a email that exists in the system + When the client wants to update all their contact phone number to already existing email + Then the informtion is not updated version 2 + + + + diff --git a/System/src/main/resources/ContactClient.feature b/System/src/main/resources/ContactClient.feature index 35557d4..ccc60ff 100644 --- a/System/src/main/resources/ContactClient.feature +++ b/System/src/main/resources/ContactClient.feature @@ -1,48 +1,52 @@ -#Author: your.email@your.domain.com -#Keywords Summary : -#Feature: List of scenarios. -#Scenario: Business rule through list of steps with arguments. -#Given: Some precondition step -#When: Some key actions -#Then: To observe outcomes or validation -#And,But: To enumerate more Given,When,Then steps -#Scenario Outline: List of steps for data-driven as an Examples and -#Examples: Container for s table -#Background: List of steps run before each of the scenarios -#""" (Doc Strings) -#| (Data Tables) -#@ (Tags/Labels):To group Scenarios -#<> (placeholder) -#"" -## (Comments) -#Sample Feature Definition Template -@tag -Feature: Contacting clients - I want to use this template for my feature file - - @tag1 - Scenario: Contacting registered client by unique id - Given registered client - When the company searches for the client by id - Then the company gets all the info of the client - - Scenario: Contacting registered client by name - Given atleast 2 registered clients with the same name - When the company searches for the client by name - Then the company gets all the info of the client of both clients - - - Scenario: Contacting client by id that doesnt exists - Given a registery - When the company searches for the client by the non existing id - Then the company does not get any info - - - Scenario: Contacting client by name that doesnt exists - Given a registery - When the company searches for the client by the non existing name - Then the company does not get any info - - - - +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Contacting clients + Company wants to have access to clients personal information to contact them + + @tag1 + Scenario: Contacting registered client by unique id + Given registered client2 + When the company searches for the client by id + Then the company gets all the info of the client + + + Scenario: Contacting registered client by name + Given atleast 2 registered clients with the same name + When the company searches for the client by name + Then the company gets all the info of the client of both clients + + + Scenario: Contacting client by id that doesnt exists + Given a registery + When the company searches for the client by the non existing id + Then the company does not get any info + + + Scenario: Contacting client by name that doesnt exists + Given a registery + When the company searches for the client by the non existing name + Then the company does not get any info + + Scenario: Contacting registered client by email + Given registered client2 + When the company searches for the client by email + Then the company gets all the info of the client + + diff --git a/System/src/main/resources/CreateJourney.feature b/System/src/main/resources/CreateJourney.feature new file mode 100644 index 0000000..5bc7338 --- /dev/null +++ b/System/src/main/resources/CreateJourney.feature @@ -0,0 +1,69 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Creating a journey + + @tag1 + Scenario: Successfully create a journey + Given origin "Copenhagen" + And destination "Oslo" + And departure date "30/04/2021" + And arrival date "31/04/2021" + When creating journey + Then confirm journey creation "Journey has been created" 020 + And assign a journey-ID + + @tag2 + Scenario: Deny journey creation due to missing parameters + When creating journey + Then deny journey creation "Necessary parameters are not entered" 210 + + @tag3 + Scenario: Deny journey creation due to missing origin + Given destination "Oslo" + And departure date "30/04/2021" + And arrival date "31/04/2021" + When creating journey + Then deny journey creation "Necessary parameters are not entered" 210 + + @tag4 + Scenario: Deny journey creation due to missing destination + Given origin "Copenhagen" + And departure date "30/04/2021" + And arrival date "31/04/2021" + When creating journey + Then deny journey creation "Necessary parameters are not entered" 210 + + @tag5 + Scenario: Deny journey creation due to missing departure date + Given origin "Copenhagen" + And destination "Oslo" + And arrival date "31/04/2021" + When creating journey + Then deny journey creation "Necessary parameters are not entered" 210 + + @tag6 + Scenario: Deny journey creation due to missing arrival date + Given origin "Copenhagen" + And destination "Oslo" + And departure date "30/04/2021" + When creating journey + Then deny journey creation "Necessary parameters are not entered" 210 + \ No newline at end of file diff --git a/System/src/main/resources/FindContainer.feature b/System/src/main/resources/FindContainer.feature new file mode 100644 index 0000000..7b7dcc0 --- /dev/null +++ b/System/src/main/resources/FindContainer.feature @@ -0,0 +1,77 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Finding containers + + @tag1 + Scenario: Find containers according to container-ID + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "containerID" specified as 2 + Then show containers with container-ID 2 + + @tag2 + Scenario: Find containers according to client-ID + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "owner" specified as 234 + Then show containers with client-ID 234 + + @tag3 + Scenario: Find containers according to position + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "position" specified as "Copenhagen" + Then show containers with position "Copenhagen" + + @tag4 + Scenario: Find containers according to content-type + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "contentType" specified as "Fish" + Then show containers with content-type "Fish" + + @tag5 + Scenario: Find containers according to company + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "company" specified as "Botanica" + Then show containers with company "Botanica" + + @tag6 + Scenario: Find containers according to journey-ID + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "journeyID" specified as "CO02292" + Then show containers with journey-ID "CO02292" + + @tag7 + Scenario: Find containers according to availability + Given 5 containers containing "Plants" registered by client 234 regulated by "Botanica" to journey "CO02292" positioned in "Copenhagen" + And 2 containers containing "Flowers" registered by client 234 regulated by "Botanica" to journey "AC02391" positioned in "Esbjerg" + And 3 containers containing "Fish" registered by client 67 regulated by "CaptainFish" to journey "CO02292" positioned in "Copenhagen" + When finding containers based on criteria "availability" specified as false + Then show all occupied containers \ No newline at end of file diff --git a/System/src/main/resources/FindJourney.feature b/System/src/main/resources/FindJourney.feature index e2f6783..0a7edfb 100644 --- a/System/src/main/resources/FindJourney.feature +++ b/System/src/main/resources/FindJourney.feature @@ -18,44 +18,84 @@ #Sample Feature Definition Template @tag -Feature: Finding a journey +Feature: Finding journeys - @tag1 - Scenario: Find journeys according to origin - Given 5 containers containing "Fish" registered to journey "CO02292" by client 234 from "Copenhagen" to "Oslo" regulated by "Maersk" - And 2 containers containing "Flowers" registered to journey "AC02391" by client 234 from "Amsterdam" to "Copenhagen" regulated by "SeaLand" - And 3 containers containing "Fish" registered to journey "CO02292" by client 67 from "Copenhagen" to "Oslo" regulated by "Maersk" + @tag1 + Scenario: Find client journeys according to journey-ID + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "journeyID" specified as "CO02292" for client 234 + Then show journeys with journey-ID "CO02292" of client 234 + + @tag2 + Scenario: Find client journeys according to origin + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" When finding based on criteria "origin" specified as "Copenhagen" for client 234 Then show journeys with origin "Copenhagen" of client 234 - @tag2 - Scenario: Find journeys according to destination - Given 5 containers containing "Fish" registered to journey "CO02292" by client 234 from "Copenhagen" to "Oslo" regulated by "Maersk" - And 2 containers containing "Flowers" registered to journey "AC02391" by client 234 from "Amsterdam" to "Copenhagen" regulated by "SeaLand" - And 3 containers containing "Fish" registered to journey "CO02292" by client 67 from "Copenhagen" to "Oslo" regulated by "Maersk" + @tag3 + Scenario: Find client journeys according to destination + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" When finding based on criteria "destination" specified as "Oslo" for client 234 Then show journeys with destination "Oslo" of client 234 - @tag3 - Scenario: Find journeys according to content-type - Given 5 containers containing "Fish" registered to journey "CO02292" by client 234 from "Copenhagen" to "Oslo" regulated by "Maersk" - And 2 containers containing "Flowers" registered to journey "AC02391" by client 234 from "Amsterdam" to "Copenhagen" regulated by "SeaLand" - And 3 containers containing "Fish" registered to journey "CO02292" by client 67 from "Copenhagen" to "Oslo" regulated by "Maersk" - When finding based on criteria "content-type" specified as "Fish" for client 234 - Then show journeys with content-type "Fish" of client 234 - @tag4 - Scenario: Find journeys according to company - Given 5 containers containing "Fish" registered to journey "CO02292" by client 234 from "Copenhagen" to "Oslo" regulated by "Maersk" - And 2 containers containing "Flowers" registered to journey "AC02391" by client 234 from "Amsterdam" to "Copenhagen" regulated by "SeaLand" - And 3 containers containing "Fish" registered to journey "CO02292" by client 67 from "Copenhagen" to "Oslo" regulated by "Maersk" - When finding based on criteria "company" specified as "Maersk" for client 234 - Then show journeys with company "Maersk" of client 234 + Scenario: Find client journeys according to departure date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "departureDate" specified as "30/04/2021" for client 234 + Then show journeys with departure date "30/04/2021" of client 234 @tag5 - Scenario: Find all journeys - Given 5 containers containing "Fish" registered to journey "CO02292" by client 234 from "Copenhagen" to "Oslo" regulated by "Maersk" - And 2 containers containing "Flowers" registered to journey "AC02391" by client 234 from "Amsterdam" to "Copenhagen" regulated by "SeaLand" - And 3 containers containing "Fish" registered to journey "CO02292" by client 67 from "Copenhagen" to "Oslo" regulated by "Maersk" - When finding based on criteria "none" specified as "unspecified" for client 234 - Then show all journeys of client 234 + Scenario: Find client journeys according to arrival date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "arrivalDate" specified as "31/04/2021" for client 234 + Then show journeys with arrival date "31/04/2021" of client 234 + + @tag6 + Scenario: Find journeys according to journey-ID + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "journeyID" specified as "CO02292" + Then show journeys with journey-ID "CO02292" + + @tag7 + Scenario: Find journeys according to origin + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "origin" specified as "Copenhagen" + Then show journeys with origin "Copenhagen" + + @tag8 + Scenario: Find journeys according to destination + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "destination" specified as "Oslo" + Then show journeys with destination "Oslo" + + @tag9 + Scenario: Find journeys according to departure date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "departureDate" specified as "30/04/2021" + Then show journeys with departure date "30/04/2021" + + @tag10 + Scenario: Find journeys according to arrival date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "20/05/2021" and arriving "21/05/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + When finding based on criteria "arrivalDate" specified as "31/04/2021" + Then show journeys with arrival date "31/04/2021" diff --git a/System/src/main/resources/ManageJourneys.feature b/System/src/main/resources/ManageJourneys.feature deleted file mode 100644 index 970aedb..0000000 --- a/System/src/main/resources/ManageJourneys.feature +++ /dev/null @@ -1,55 +0,0 @@ -#Author: Group 2 -#Keywords Summary : -#Feature: List of scenarios. -#Scenario: Business rule through list of steps with arguments. -#Given: Some precondition step -#When: Some key actions -#Then: To observe outcomes or validation -#And,But: To enumerate more Given,When,Then steps -#Scenario Outline: List of steps for data-driven as an Examples and -#Examples: Container for s table -#Background: List of steps run before each of the scenarios -#""" (Doc Strings) -#| (Data Tables) -#@ (Tags/Labels):To group Scenarios -#<> (placeholder) -#"" -## (Comments) -#Sample Feature Definition Template - -@tag -Feature: Managing journeys information - - @tag1 - Scenario: Update the current position of a container - Given logistic company "Maersk" - And 5 containers registered to journey "CO02292" from "Copenhagen" to "Oslo" regulated by "Maersk" - When updating containers current position of journey "CO02292" to "Gothenburg" - Then confirm updating "Position has been updated" 070 - - @tag2 - Scenario: Deny updating because the journey was not found - Given logistic company "Maersk" - When updating containers current position of journey "CO02292" to "Gothenburg" - Then updating "Journey not found" 140 - - @tag3 - Scenario: Deny updating because the journey was not found - Given logistic company "Maersk" - And 5 containers registered to journey "CO02292" from "Copenhagen" to "Oslo" regulated by "Maersk" - When updating containers current position of journey "CO00002" to "Gothenburg" - Then confirm updating "Journey not found" 140 - - @tag4 - Scenario: Complete a journey and remove it from the record - Given logistic company "Maersk" - And 5 containers registered to journey "CO02292" from "Copenhagen" to "Oslo" regulated by "Maersk" - When completing journey "CO02292" - Then remove from journey database - - @tag5 - Scenario: Deny completion because the journey was not found - Given logistic company "Maersk" - When completing journey "CO02292" - Then deny removal - diff --git a/System/src/main/resources/ManagementJsonDatabase.feature b/System/src/main/resources/ManagementJsonDatabase.feature new file mode 100644 index 0000000..f7ec77f --- /dev/null +++ b/System/src/main/resources/ManagementJsonDatabase.feature @@ -0,0 +1,49 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Management of Json databases + + @tag1 + Scenario: Successfully produce program databases + When producing client, container and journey databases + Then confirm producing + + @tag2 + Scenario: Successfully update program databases + Given client, container and journey databases + And unsaved data + When saving + Then confirm database updates + + @tag3 + Scenario: Successfully produce and update program databases in case if they do not exist when updating + Given unsaved data + When saving + Then confirm database updates + + @tag4 + Scenario: Successfully produce empty program databases when saving without data + When saving + Then confirm producing + + @tag5 + Scenario: Unsuccessful pull when the databases do not exist + When pulling + Then fail \ No newline at end of file diff --git a/System/src/main/resources/RegisterClients.feature b/System/src/main/resources/RegisterClients.feature index 4b4614e..72301e5 100644 --- a/System/src/main/resources/RegisterClients.feature +++ b/System/src/main/resources/RegisterClients.feature @@ -1,73 +1,70 @@ -#Author: your.email@your.domain.com -#Keywords Summary : -#Feature: List of scenarios. -#Scenario: Business rule through list of steps with arguments. -#Given: Some precondition step -#When: Some key actions -#Then: To observe outcomes or validation -#And,But: To enumerate more Given,When,Then steps -#Scenario Outline: List of steps for data-driven as an Examples and -#Examples: Container for s table -#Background: List of steps run before each of the scenarios -#""" (Doc Strings) -#| (Data Tables) -#@ (Tags/Labels):To group Scenarios -#<> (placeholder) -#"" -## (Comments) -#Sample Feature Definition Template -@tag -Feature: Register clients - I want to use this template for my feature file - - @tag1 - Scenario: A client is registering in the system with date of birth, full name and email, phone number - Given a new client with name "Alice Allison" - And born 01012000 - And with email "AliceAllison@gmail.com" - And with phone number 12345678 - When the company registers the client - Then the client is registered in the system successfully - And the client is assigned a unique company ID 1 - - - Scenario: Same client registers again - Given a registered client - When the registered client tries to register again - Then the client is not registered in the system again - - - Scenario: Two client with same name but different contact info register - Given an already registered client - When a new client registers with the same name but different contact info - Then the new client is registered in the system successfully - And both clients have different unique company IDs - - - Scenario: Client tries to register without name - Given a client without a name - And born 01012000 - And with email "AliceAllison@gmail.com" - And with phone number 12345678 - When they try to regsiter without a name - Then then the client is not registered in the system - - - - Scenario: Client tries to register with one contact info - Given a client with all info except email - When they try to regsiter without an email - Then then the client is registered in the system successfully - - - Scenario: Client tries to register with the other contact info - Given a client with all info except phone number - When they try to regsiter without an phone number - Then then the client without the phone numver is registered in the system successfully - - - - - - - +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Register clients + Company adds clients + + @tag1 + Scenario: A client is registering in the system with date of birth, full name and email, phone number + Given a new client with name "Alice Allison" + And born "01012000" + And with email "AliceAllison@gmail.com" + And with phone number "12345678" + When the company registers the client + Then the client is registered in the system successfully + And the client is assigned a unique company ID 1 + + + Scenario: Same client registers again + Given a registered client + When the registered client tries to register again + Then the client is not registered in the system again + + + Scenario: Two client with same name but different contact info register + Given an already registered client + When a new client registers with the same name but different contact info + Then the new client is registered in the system successfully + And both clients have different unique company IDs + + + Scenario: Client tries to register without name + Given a client without a name + When they try to regsiter without a name + Then then the client is not registered in the system + + + + Scenario: Client tries to register with one contact info + Given a client with all info except email + When they try to regsiter without an email + Then then the client is registered in the system successfully + + + Scenario: Client tries to register with the other contact info + Given a client with all info except phone number + When they try to regsiter without an phone number + Then then the client without the phone numver is registered in the system successfully + + + + + + + diff --git a/System/src/main/resources/RegisterContainer.feature b/System/src/main/resources/RegisterContainer.feature index 92b1441..745754c 100644 --- a/System/src/main/resources/RegisterContainer.feature +++ b/System/src/main/resources/RegisterContainer.feature @@ -16,61 +16,18 @@ #"" ## (Comments) #Sample Feature Definition Template + @tag -Feature: Registering containers +Feature: Registering a container - @tag1 - Scenario: Register containers - Given location "Copenhagen" - And content-type "Fish" - And company "Maersk" - And number of containers 5 - And shipping yard in "Copenhagen" with 20 containers - When registering - Then confirm registering "Container has been registered" 010 - - @tag2 - Scenario: Register fewer containers than requested - Given location "Copenhagen" - And content-type "Fish" - And company "Maersk" - And number of containers 5 - And shipping yard in "Copenhagen" with 3 containers - When registering - Then confirm registering "Container has been registered" 010 - - @tag3 - Scenario: Deny registering due to unavailable containers + @tag1 + Scenario: Successfully register a container Given location "Copenhagen" - And content-type "Fish" - And company "Maersk" - And number of containers 5 - When registering - Then deny registering "Container not found" 111 - - @tag4 - Scenario: Deny registering due to missing content type - Given location "Copenhagen" - And company "Maersk" - And number of containers 5 - And shipping yard in "Copenhagen" with 20 containers - When registering - Then deny registering "Necessary parameters not entered" 110 - - @tag5 - Scenario: Deny registering due to missing company - Given location "Copenhagen" - And content-type "Fish" - And number of containers 5 - And shipping yard in "Copenhagen" with 20 containers - When registering - Then deny registering "Necessary parameters not entered" 110 - - @tag6 - Scenario: Deny registering due to missing company and content-type - Given location "Copenhagen" - And number of containers 5 - And shipping yard in "Copenhagen" with 20 containers - When registering - Then deny registering "Necessary parameters not entered" 110 - \ No newline at end of file + When registering container + Then confirm registration "Container has been registered" 010 + + @tag2 + Scenario: Deny registering a container due to missing location + When registering container + Then deny registration "Location is not valid" 162 + diff --git a/System/src/main/resources/RegisterToJourney.feature b/System/src/main/resources/RegisterToJourney.feature index 8b1f889..40b759c 100644 --- a/System/src/main/resources/RegisterToJourney.feature +++ b/System/src/main/resources/RegisterToJourney.feature @@ -16,13 +16,14 @@ #"" ## (Comments) #Sample Feature Definition Template + @tag Feature: Register client containers to a journey @tag1 Scenario: Register to a journey Given journey "CO02292" from "Copenhagen" to "Oslo" - And 2 registered containers from "Copenhagen" + And 2 booked containers from "Copenhagen" And origin "Copenhagen" And destination "Oslo" When registering to "CO02292" @@ -31,44 +32,44 @@ Feature: Register client containers to a journey @tag2 Scenario: Deny registering due to unavailable journey Given journey "AO02292" from "Amsterdam" to "Oslo" - And 2 registered containers from "Copenhagen" + And 2 booked containers from "Copenhagen" And origin "Copenhagen" And destination "Oslo" When registering to "CO02292" - Then deny registering "Journey not found" 140 + Then deny registering "Journey is not found" 120 @tag3 Scenario: Deny registering due to unavailable container Given journey "CO02292" from "Copenhagen" to "Oslo" - And 0 registered containers from "Copenhagen" + And 0 booked containers from "Copenhagen" And origin "Copenhagen" And destination "Oslo" When registering to "CO02292" - Then deny registering "Container not found" 111 + Then deny registering "Container is not found" 110 @tag4 - Scenario: Deny assigning due to unavailable journey because of different origin and destination + Scenario: Deny registering due to unavailable journey because of different origin and destination Given journey "CO02292" from "Copenhagen" to "Oslo" - And 2 registered containers from "Copenhagen" + And 2 booked containers from "Copenhagen" And origin "Amsterdam" And destination "Oslo" When registering to "CO02292" - Then deny registering "Journey not found" 140 + Then deny registering "Journey is not found" 120 @tag5 - Scenario: Deny assigning due to unavailable journey because of different origin + Scenario: Deny registering due to unavailable journey because of different origin Given journey "CO02292" from "Copenhagen" to "Oslo" - And 2 registered containers from "Copenhagen" + And 2 booked containers from "Copenhagen" And origin "Amsterdam" And destination "Oslo" When registering to "CO02292" - Then deny registering "Journey not found" 140 + Then deny registering "Journey is not found" 120 @tag6 - Scenario: Deny assigning due to unavailable journey because of different destination + Scenario: Deny registering due to unavailable journey because of different destination Given journey "CO02292" from "Copenhagen" to "Oslo" - And 2 registered containers from "Copenhagen" + And 2 booked containers from "Copenhagen" And origin "Copenhagen" And destination "Amsterdam" When registering to "CO02292" - Then deny registering "Journey not found" 140 \ No newline at end of file + Then deny registering "Journey is not found" 120 \ No newline at end of file diff --git a/System/src/main/resources/RemoveContainer.feature b/System/src/main/resources/RemoveContainer.feature new file mode 100644 index 0000000..a6753c0 --- /dev/null +++ b/System/src/main/resources/RemoveContainer.feature @@ -0,0 +1,46 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Remove container from registry + + @tag1 + Scenario: Successfully remove the selected container + Given a container with ID 22 + And a container with ID 77 + And a container with ID 200 + When removing container number 1 + Then confirm removing of a container with ID 77 + + @tag2 + Scenario: Successfully remove the selected container + Given a container with ID 22 + And a container with ID 77 + And a container with ID 200 + When removing container number 2 + And removing container number 1 + And removing container number 0 + Then confirm removing of a container with ID 200 + Then confirm removing of a container with ID 77 + Then confirm removing of a container with ID 22 + + @tag3 + Scenario: Restrict removing when there is nothing to select + When removing container number 1 + Then pass \ No newline at end of file diff --git a/System/src/main/resources/RemoveJourney.feature b/System/src/main/resources/RemoveJourney.feature new file mode 100644 index 0000000..dc82e51 --- /dev/null +++ b/System/src/main/resources/RemoveJourney.feature @@ -0,0 +1,71 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Complete and remove journey from registry + + @tag1 + Scenario: Complete a journey and remove it from the registry + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When completing journey "CO02292" + Then confirm completing and removing of the journey "Journey has been completed and successfully removed" 021 + + @tag2 + Scenario: Deny completion because the journey was not found + When completing journey "CO02292" + Then deny completing "Journey is not found" 120 + + @tag3 + Scenario: Deny completion because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When completing journey "CO00002" + Then deny completing "Journey is not found" 120 + + @tag4 + Scenario: Remove a container from a journey + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When removing a container with ID 2 from journey "CO02292" + Then confirm container removing "Container has been successfully removed" 011 + + @tag5 + Scenario: Deny completion because the journey was not found + When removing a container with ID 2 from journey "CO02292" + Then deny container removing "Journey is not found" 120 + + @tag6 + Scenario: Deny completion because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When removing a container with ID 2 from journey "CO00002" + Then deny container removing "Journey is not found" 120 + + @tag7 + Scenario: Deny completion because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When removing a container with ID 12 from journey "CO02292" + Then deny container removing "Container is not found" 110 diff --git a/System/src/main/resources/SeeingInformation.feature b/System/src/main/resources/SeeingInformation.feature new file mode 100644 index 0000000..c958cef --- /dev/null +++ b/System/src/main/resources/SeeingInformation.feature @@ -0,0 +1,36 @@ +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Seeing the info of containers + + + @tag1 + Scenario: Successful seeing of info + Given a container with id 100 and owner 1000 + And a client with id 1000 + When requesting to see info for container 100 + Then history of container is shown + + @tag2 + Scenario: Unsuccessful seeing of info because container does not belong to the client + Given a container with id 100 and owner 1000 + And a client with id 2000 + When requesting to see info for container 100 + Then history of container is not shown + diff --git a/System/src/main/resources/SharingInformation.feature b/System/src/main/resources/SharingInformation.feature new file mode 100644 index 0000000..7b4fbf3 --- /dev/null +++ b/System/src/main/resources/SharingInformation.feature @@ -0,0 +1,42 @@ +#Author: your.email@your.domain.com +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template +@tag +Feature: Sharing information + I registed client wants to share their information with another client and the other client wants to see the registed client's information + + @tag1 + Scenario: Send your information to another client successfully + Given two registed clients2 + When one client sends his information to the other client + Then The information is successfully sent + + @tag1 + Scenario: Send your information to another client unsuccessfully + Given one registed client and his unregisted friend + When one client sends his information to the unregisted client + Then The information is not successfully sent + + + @tag1 + Scenario: being able to access friend's shared information + Given two registed clients2 + When one client tries to access his friend's information + Then The information received successfully. + + diff --git a/System/src/main/resources/UpdateContainer.feature b/System/src/main/resources/UpdateContainer.feature new file mode 100644 index 0000000..14105f0 --- /dev/null +++ b/System/src/main/resources/UpdateContainer.feature @@ -0,0 +1,59 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Updating containers information + + @tag1 + Scenario: Update the current position of a container + Given 8 containers registered by client 234 to journey "CO02292" positioned in "Copenhagen" + And 2 containers registered by client 67 to journey "AC02391" positioned in "Amsterdam" + When updating containers current position with current journey "CO02292" to "Gothenburg" + Then confirm position updating "Position has been updated" 070 + + @tag2 + Scenario: Deny position updating because the container was not found + When updating containers current position with current journey "CO02292" to "Gothenburg" + Then deny position updating "Container is not found" 110 + + @tag3 + Scenario: Deny position updating because the container was not found + Given 8 containers registered by client 234 to journey "CO02292" positioned in "Copenhagen" + And 2 containers registered by client 67 to journey "AC02391" positioned in "Amsterdam" + When updating containers current position with current journey "CO02272" to "Gothenburg" + Then deny position updating "Container is not found" 110 + + @tag4 + Scenario: Update the current journey label of a container to arrived + Given 8 containers registered by client 234 to journey "CO02292" positioned in "Copenhagen" + And 2 containers registered by client 67 to journey "AC02391" positioned in "Amsterdam" + When updating containers current journey label with current journey "CO02292" + Then confirm journey label updating "Journey label has been updated" 022 + + @tag5 + Scenario: Deny updating of the current journey label because the container was not found + When updating containers current journey label with current journey "CO02272" + Then deny journey label updating "Container is not found" 110 + + @tag6 + Scenario: Deny updating of the current journey label because the container was not found + Given 8 containers registered by client 234 to journey "CO02292" positioned in "Copenhagen" + And 2 containers registered by client 67 to journey "AC02391" positioned in "Amsterdam" + When updating containers current journey label with current journey "CO02272" + Then deny journey label updating "Container is not found" 110 \ No newline at end of file diff --git a/System/src/main/resources/UpdateJourney.feature b/System/src/main/resources/UpdateJourney.feature new file mode 100644 index 0000000..1e2801a --- /dev/null +++ b/System/src/main/resources/UpdateJourney.feature @@ -0,0 +1,100 @@ +#Author: Group 2 +#Keywords Summary : +#Feature: List of scenarios. +#Scenario: Business rule through list of steps with arguments. +#Given: Some precondition step +#When: Some key actions +#Then: To observe outcomes or validation +#And,But: To enumerate more Given,When,Then steps +#Scenario Outline: List of steps for data-driven as an Examples and +#Examples: Container for s table +#Background: List of steps run before each of the scenarios +#""" (Doc Strings) +#| (Data Tables) +#@ (Tags/Labels):To group Scenarios +#<> (placeholder) +#"" +## (Comments) +#Sample Feature Definition Template + +@tag +Feature: Updating journeys information + + @tag1 + Scenario: Update the current position of containers + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating containers current position of journey "CO02292" to "Gothenburg" + Then confirm updating "Position has been updated" 070 + + @tag2 + Scenario: Deny updating because the journey was not found + When updating containers current position of journey "CO02292" to "Gothenburg" + Then deny updating "Journey is not found" 120 + + @tag3 + Scenario: Deny updating because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating containers current position of journey "CO00002" to "Gothenburg" + Then deny updating "Journey is not found" 120 + + @tag4 + Scenario: Deny updating because containers were not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 0 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating containers current position of journey "AC02391" to "Esbjerg" + Then deny updating "Container is not found" 110 + + @tag5 + Scenario: Update the current departure date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating current departure date of journey "CO02292" to "25/05/2021" + Then confirm updating "Departure date has been set" 071 + + @tag6 + Scenario: Deny updating because the journey was not found + When updating current departure date of journey "CO02292" to "25/05/2021" + Then deny updating "Journey is not found" 120 + + @tag7 + Scenario: Deny updating because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating current departure date of journey "CO00002" to "25/05/2021" + Then deny updating "Journey is not found" 120 + + @tag8 + Scenario: Update the current journey label of containers to arrived and set todays arrival date + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating current arrival date of journey "CO02292" to todays date and setting the current journey label of containers to arrived + Then confirm updating "Arrival date has been set" 072 + + @tag9 + Scenario: Deny updating because the journey was not found + When updating current arrival date of journey "CO02292" to todays date and setting the current journey label of containers to arrived + Then deny updating "Journey is not found" 120 + + @tag10 + Scenario: Deny updating because the journey was not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 2 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating current arrival date of journey "CO00002" to todays date and setting the current journey label of containers to arrived + Then deny updating "Journey is not found" 120 + + @tag11 + Scenario: Deny updating because containers were not found + Given 5 containers registered by client 234 to journey "CO02292" from "Copenhagen" to "Oslo" departing "30/04/2021" and arriving "31/04/2021" + And 0 containers registered by client 234 to journey "AC02391" from "Amsterdam" to "Copenhagen" departing "30/04/2021" and arriving "31/04/2021" + And 3 containers registered by client 67 to journey "CO02292" from "Copenhagen" to "Oslo" departing "20/05/2021" and arriving "21/05/2021" + When updating current arrival date of journey "AC02391" to todays date and setting the current journey label of containers to arrived + Then deny updating "Container is not found" 110 \ No newline at end of file diff --git a/System/src/main/resources/UpdateJsonDatabase.feature b/System/src/main/resources/UpdateJsonDatabase.feature deleted file mode 100644 index 9d36438..0000000 --- a/System/src/main/resources/UpdateJsonDatabase.feature +++ /dev/null @@ -1,54 +0,0 @@ -#Author: Group 2 -#Keywords Summary : -#Feature: List of scenarios. -#Scenario: Business rule through list of steps with arguments. -#Given: Some precondition step -#When: Some key actions -#Then: To observe outcomes or validation -#And,But: To enumerate more Given,When,Then steps -#Scenario Outline: List of steps for data-driven as an Examples and -#Examples: Container for s table -#Background: List of steps run before each of the scenarios -#""" (Doc Strings) -#| (Data Tables) -#@ (Tags/Labels):To group Scenarios -#<> (placeholder) -#"" -## (Comments) -#Sample Feature Definition Template -@tag -Feature: Update Json database - I want to use this template for my feature file - - @tag1 - Scenario: Successful update of Json file - Given unsaved data - And a Json file "journey_database.json" - When Saving to Json file - Then Confirm update - - @tag2 - Scenario: Unsuccessful update due to missing Json file - Given unsaved data - When Saving to Json file - Then Deny update - - @tag3 - Scenario: Successful deletion of data from Json file - Given information to be removed - And a Json file "journey_database.json" - When Deleting from Json file - Then Confirm deletion - - @tag4 - Scenario: Unsuccessful deletion due to missing Json file - Given information to be removed - When Deleting from Json file - Then Deny deletion - - @tag5 - Scenario: Unsuccessful deletion due to information not existing in Json file - Given information to be removed that does not exist in given Json file - And a Json file "journey_database.json" - When Deleting from Json file - Then Deny deletion diff --git a/System/src/test/java/ClientDatabaseTest.java b/System/src/test/java/ClientDatabaseTest.java new file mode 100644 index 0000000..8df3ed6 --- /dev/null +++ b/System/src/test/java/ClientDatabaseTest.java @@ -0,0 +1,284 @@ + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import io.cucumber.java.Before; +import management.Client; +import management.ClientDatabase; +import management.ContainerDatabase; +import management.LogisticsCompany; + +public class ClientDatabaseTest { + + private Client client; + private LogisticsCompany company; + private ClientDatabase database; + + @Before + public void createClient() { + client = new Client(); + company = LogisticsCompany.getInstance(); + + } + + @Test + public void testGetClientsandSetClients() { + + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + + + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998", "0000"); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Javier" ,"Almendra", "21/04/2021", "Javier.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + + database.setClients(clients); + + assertTrue(clients.size() == database.getClients().size()); + + } + + + + @Test + public void testAllowedUpdate() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + + + Client client1 = new Client("JJ", "Mansour", "21/04/2021", "JJ.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Roro" ,"Almendra", "21/04/2021", "Roro.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Lolo" ,"Korboe", "21/04/2021", "Lolo.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + + assertTrue("not updates", database.allowedUpdate(100000, "Alan.Mansour1@mail.com")); + assertFalse("updates", database.allowedUpdate(100000, "Roro.Almendra@mail.com")); + assertFalse("phone number updates", database.allowedUpdate(100000, "+999-999-99-999")); + + } + + @Test + public void testGetPassword() { + + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + + + Client client1 = new Client("JJ", "Mansour", "21/04/2021", "JJ.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Roro" ,"Almendra", "21/04/2021", "Roro.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + client2.setPassword("0001"); + clients.add(client2); + Client client3 = new Client("Lolo" ,"Korboe", "21/04/2021", "Lolo.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + + assertTrue("not correct password", "0000".equals(database.getPassword("JJ.Mansour@mail.com"))); + assertFalse("correct password", "0000".equals(database.getPassword("Roro.Almendra@mail.com"))); + assertFalse("correct password", "0000".equals(database.getPassword("Roro111.Almendra@mail.com"))); + assertTrue(database.getClient(0).isEmpty()) ; + assertFalse(database.getClient(100000).isEmpty()) ; + + } + + @Test (expected = IndexOutOfBoundsException.class) + public void testGetClientbyEmail() { + + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + + + Client client1 = new Client("Yoyo", "Mansour", "21/04/2021", "Yoyo.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(client1.equals(database.getClient("Yoyo.Mansour@mail.com").get(0))); + assertFalse(client1.equals(database.getClient("Boyo.Mansour@mail.com").get(0))); + + } + + @Test + public void testLegalEmailToAddClient() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("Yoyo", "Mansour", "21/04/2021", "Yoyo.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Gogo", "Mansour", "21/04/2021", "Yoyo.Mansour@mail.com", "+999-999-99-999"); + client2.setId(100000); + client2.setPassword("0000"); + clients.add(client2); + + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + + assertFalse(database.legalEmailToAddClient(client2)); + + + } + + @Test + public void testLegalPhoneNumberToAddClient() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("Dodo", "Mansour", "21/04/2021", "DoDo.Mansour@mail.com", "+999-999-99-99800000"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertFalse(database.legalPhoneNumberToAddClient(client1)); + } + + @Test + public void testClientExists() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("Gogo", "Mansour", "21/04/2021", "Gogo.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client c = new Client(); + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(database.ClientExists(client1)); + assertFalse(database.ClientExists(c)); + } + + @Test + public void testCheckID() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("Fogo", "Mansour", "21/04/2021", "Fogo.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client c = new Client(); + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(database.checkID(client1)); + assertFalse(database.checkID(c)); + } + + + + @Test + public void testCheckUpdatedInfo() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("Fofo", "Mansour", "21/04/2021", "Fofo.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + database.setClients(clients); + try { + database.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + assertTrue(database.checkUpdatedInfo("Fofo", "Mansour", "21/04/2021", "Fofo.Mansour@mail.com", "+999-999-99-998")); + assertFalse(database.checkUpdatedInfo("Itsyaboi", "Lolo", "21/04/2021", "Fofo1.Mansour@mail.com", "+999-999-99-998")); + assertFalse(database.checkUpdatedInfo("Fofo", "Mansourooo", "21/04/2021", "Fofo.Mansour@mail.com", "+999-999-99-998")); + assertFalse(database.checkUpdatedInfo("Fofo", "Mansour", "21/04/2021111", "Fofo.Mansour@mail.com", "+999-999-99-998")); + assertFalse(database.checkUpdatedInfo("Fofo", "Mansour", "21/04/2021", "Fofo1111.Mansour@mail.com", "+999-999-99-998")); + assertFalse(database.checkUpdatedInfo("Fofo", "Mansour", "21/04/2021", "Fofo.Mansour@mail.com", "12345678")); + } + + + + @Test (expected = IndexOutOfBoundsException.class) + public void testGetClientStringString() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("JoJo", "Mansour", "21/04/2021", "Jojo.Mansour@mail.com", "+999-999-99-990"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client c = new Client(); + database.setClients(clients); + + + assertTrue(client1.equals(database.getClient("JoJo", "Mansour").get(0))); + assertFalse(c.equals(database.getClient("JoJo1", "Mansour").get(0))); + } + + @Test (expected = IndexOutOfBoundsException.class) + public void testGetClientString() { + ArrayList clients = new ArrayList(); + database = new ClientDatabase(); + Client client1 = new Client("BloBlo", "Mansour", "21/04/2021", "BloBlo.Mansour@mail.com", "+999-999-99-997"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client c = new Client(); + database.setClients(clients); + + + assertTrue(client1.equals(database.getClient("BloBlo.Mansour@mail.com").get(0))); + assertFalse(c.equals(database.getClient("BloBlo11.Mansour@mail.com").get(0))); + } + +} diff --git a/System/src/test/java/ClientTest.java b/System/src/test/java/ClientTest.java new file mode 100644 index 0000000..25087d7 --- /dev/null +++ b/System/src/test/java/ClientTest.java @@ -0,0 +1,262 @@ + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import io.cucumber.java.Before; +import management.Client; +import management.ClientDatabase; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.JourneyDatabase; +import management.LogisticsCompany; +import response.ResponseObject; + + +public class ClientTest { + private Client client; + + private LogisticsCompany company; + private Client myContainers; + private ContainerDatabase containers; + private ArrayList container; + + @Before + public void createClient() { + client = new Client(); + company = LogisticsCompany.getInstance(); + myContainers = new Client(); + containers = new ContainerDatabase(); + } + + + @Test + public void testGetIdandSetId() { + client = new Client(); + client.setId(100000); + assertTrue("Id is not 100000", client.getId() == 100000); + + + } + + + @Test + public void testGetfirstNameandSetfirstName() { + client = new Client(); + client.setfirstName("Alice"); + assertTrue("First name is not Alice", "Alice".equals(client.getfirstName())); + } + + + + @Test + public void testGetlastNameandSetlastName() { + client = new Client(); + client.setlastName("Allinson"); + assertTrue("First name is not Allison", "Allinson".equals(client.getlastName())); + } + + + + @Test + public void testGetBirthDateandSetBirthDate() { + client = new Client(); + client.setBirthDate("21\04\2021"); + assertTrue("Birthdate is not correct", "21\04\2021".equals(client.getBirthDate())); + } + + @Test + public void testGetEmailandSetEmail() { + client = new Client(); + client.setEmail("Alice.Allinson@mail.com"); + assertTrue("Email is not correct", "Alice.Allinson@mail.com".equals(client.getEmail())); + + } + + + @Test + public void testGetPhoneNumberandSetPhoneNumber() { + client = new Client(); + client.setPhoneNumber("12345678"); + assertTrue("Phone number is not correct", "12345678".equals(client.getPhoneNumber())); + } + + + + @Test + public void testGetPasswordandSetPassword() { + client = new Client(); + client.setPassword("12345678"); + assertTrue("Password is not correct", "12345678".equals(client.getPassword())); + } + + + + @Test (expected = NullPointerException.class) + public void testGetMyContainersandSetMyContainers() { + + + ContainerDatabase containers = new ContainerDatabase(); + ArrayList myContainers = new ArrayList(); + + company = LogisticsCompany.getInstance(); + Client client1 = new Client(); + int counter = 1; + for (int i = 1; i <= 10; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(counter - 1).setContainerID(counter); + containers.getContainers().get(counter - 1).setPosition("Copenhagen"); + containers.getContainers().get(counter - 1).setAvailability(true); + myContainers.add(container.get(i)); + counter += 1; + } + client1.setMyContainers(myContainers); + + assertTrue(myContainers.size() == client.getMyContainers().size()); + + + + } + + + @Test (expected = NullPointerException.class) + public void testGetMyJourneysandSetMyJourneys() { + JourneyDatabase journeys = new JourneyDatabase(); + company = LogisticsCompany.getInstance(); + Client client1 = new Client(); + + Journey journey1 = new Journey(); + String journeyID1 = "CO23143"; + String origin1 = "Copenhagen"; + String destination1 = "Oslo"; + journey1.setJourneyID(journeyID1); + journey1.setOrigin(origin1); + journey1.setDestination(destination1); + journey1.setDepartureDate("21/04/2021"); + journey1.setArrivalDate("22/04/2021"); + journeys.create(journey1); + + Journey journey2 = new Journey(); + String journeyID2 = "AC21003"; + String origin2 = "Amsterdam"; + String destination2 = "Copenhagen"; + journey2.setJourneyID(journeyID2); + journey2.setOrigin(origin2); + journey2.setDestination(destination2); + journeys.create(journey2); + + client1.setMyJourneys(journeys); + assertTrue(journeys.equals(client.getMyJourneys())); + } + + + + @Test + public void testUpdateInfoStringStringStringStringStringClientDatabase() throws Exception { + ClientDatabase clients = new ClientDatabase(); + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.getClients().add(client1); + Client client2 = new Client("Javier" ,"Almendra", "21/04/2021", "Javier.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.getClients().add(client2); + Client client3 = new Client("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.getClients().add(client3); + clients.push(); + + + company = LogisticsCompany.getInstance(); + + + ResponseObject response = client1.updateInfo("Alan", "Mansour", "21/04/2021", "Alice@mail.com", "0383747858", clients); + ResponseObject response1 = client2.updateInfo("Javier" ,"Almendra", "21/04/2021", "Alice@mail.com", "+999-999-99-999", clients); + ResponseObject response2 = client3.updateInfo("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "0383747858", clients); + assertTrue("info not updated", response.getErrorCode() == 1004); + assertTrue("info updated", response1.getErrorCode() == 1005); + assertTrue("info updated", response2.getErrorCode() == 1006); + + + } + + @Test + public void testUpdateInfoStringClientDatabase() { + client = new Client(); + company = LogisticsCompany.getInstance(); + ClientDatabase registery = company.getClientDatabase(); + client.setPassword("123456"); + client.updateInfo("12345678", registery); + assertTrue("password did not update", "12345678".equals(client.getPassword())); + } + + @Test + public void testAddFriend() { + + company = LogisticsCompany.getInstance(); + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Javier" ,"Almendra", "21/04/2021", "Javier.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + + registery.setClients(clients); + client = new Client(); + company = LogisticsCompany.getInstance(); + + + ResponseObject response = client.addFriend("Alan.Mansour@mail.com", registery); + ResponseObject response1 = client.addFriend("AliceGOOO@mail.com", registery); + assertTrue("Friend not Added", response.getErrorCode() == 11560); + assertTrue("Friend Added", response1.getErrorCode() == 11021); + + + } + + @Test + public void testGetMyFriends() { + + company = LogisticsCompany.getInstance(); + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("Dodo", "Dodo", "21/04/2021", "Dodo", "+999-999-99-990"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Fodo" ,"Fodo", "21/04/2021", "Fodo.Fodo@mail.com", "+999-999-99-991"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Godo" ,"Godo", "21/04/2021", "Godo.Godo@mail.com", "+999-999-99-992"); + client3.setId(100002); + clients.add(client3); + + registery.setClients(clients); + + try { + registery.push(); + } catch (Exception e) { + e.printStackTrace(); + } + + client1.addFriend("Fodo.Fodo@mail.com", registery); + assertTrue(client2.getMyFriends(registery).size() == 1); + assertFalse(client3.getMyFriends(registery).size() == 1); + + + + + } + +} diff --git a/System/src/test/java/ContainerDatabaseTest.java b/System/src/test/java/ContainerDatabaseTest.java new file mode 100644 index 0000000..48834d5 --- /dev/null +++ b/System/src/test/java/ContainerDatabaseTest.java @@ -0,0 +1,1023 @@ + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; + +import management.Container; +import management.ContainerDatabase; +import response.ResponseObject; + +public class ContainerDatabaseTest { + private ContainerDatabase containerDatabase; + private ArrayList containers; + private Container container1; + private Container container2; + private Container container3; + private Container container4; + private ResponseObject response; + + @Before + public void setUp() { + containerDatabase = new ContainerDatabase(); + containers = new ArrayList<>(); + container1 = new Container(); + container2 = new Container(); + container3 = new Container(); + container4 = new Container(); + ResponseObject response = new ResponseObject(0,"New response object"); + } + + @Test + public void testGetContainers() { + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + + assertEquals(0, containerDatabase.getContainers().size()); + containerDatabase.setContainers(containers); + assertEquals(4, containerDatabase.getContainers().size()); + } + + @Test + public void testSetContainers() { + containers.add(container1); + containers.add(container2); + containers.add(container3); + containerDatabase.setContainers(containers); + + assertEquals(3, containerDatabase.getContainers().size()); + } + + @Test + public void testExtractIntString() { + container1.setAvailability(true); + container2.setAvailability(true); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containerDatabase.setContainers(containers); + + assertEquals(0, containerDatabase.extract(4, "Copenhagen").size()); + } + + @Test + public void testExtractIntString2() { + container1.setAvailability(true); + container2.setAvailability(true); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(0, containerDatabase.extract(0, "Copenhagen").size()); + assertEquals(1, containerDatabase.extract(1, "Copenhagen").size()); + assertEquals(2, containerDatabase.extract(2, "Copenhagen").size()); + } + + @Test + public void testExtractIntString3() { + container1.setAvailability(true); + container2.setAvailability(true); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(2, containerDatabase.extract(3, "Copenhagen").size()); + } + + @Test + public void testExtractIntString4() { + container1.setAvailability(true); + container2.setAvailability(true); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(0, containerDatabase.extract(3, "Oslo").size()); + } + + @Test + public void testExtractInt() { + container1.setAvailability(true); + container2.setAvailability(true); + container3.setAvailability(true); + container4.setAvailability(true); + container1.setOwner(2); + container2.setOwner(2); + container3.setOwner(6); + container4.setOwner(2); + containerDatabase.setContainers(containers); + + assertEquals(0, containerDatabase.extract(2).size()); + } + + @Test + public void testExtractInt2() { + container1.setAvailability(true); + container2.setAvailability(true); + container3.setAvailability(true); + container4.setAvailability(true); + container1.setOwner(2); + container2.setOwner(2); + container3.setOwner(6); + container4.setOwner(2); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(0, containerDatabase.extract(30).size()); + } + + @Test + public void testExtractInt3() { + container1.setAvailability(true); + container2.setAvailability(true); + container3.setAvailability(true); + container4.setAvailability(true); + container1.setOwner(2); + container2.setOwner(2); + container3.setOwner(6); + container4.setOwner(2); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(1, containerDatabase.extract(6).size()); + assertEquals(3, containerDatabase.extract(2).size()); + } + + @Test + public void testBook() { + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(0, "Copenhagen", "Fish", "Captain Fish", 4); + assertEquals(response.getErrorCode(), 132); + } + + @Test + public void testBook2() { + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, null, "Fish", "Captain Fish", 4); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testBook3() { + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", null, "Captain Fish", 4); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testBook4() { + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", "Fish", null, 4); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testBook5() { + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", "Fish", "Captain Fish", 0); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testBook6() { + container1.setAvailability(true); + container2.setAvailability(true); + container3.setAvailability(true); + container4.setAvailability(true); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", "Fish", "Captain Fish", 3); + assertEquals(response.getErrorCode(), 010); + } + + @Test + public void testBook7() { + container1.setAvailability(false); + container2.setAvailability(false); + container3.setAvailability(false); + container4.setAvailability(false); + container1.setPosition("Copenhagen"); + container2.setPosition("Copenhagen"); + container3.setPosition("Copenhagen"); + container4.setPosition("Copenhagen"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", "Fish", "Captain Fish", 3); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testBook8() { + containerDatabase.setContainers(containers); + + response = containerDatabase.book(4, "Copenhagen", "Fish", "Captain Fish", 3); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testFindStringInt() { + container1.setOwner(4); + container2.setOwner(4); + container3.setOwner(6); + container4.setOwner(9); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find(null, 4).size(), 0); + } + + @Test + public void testFindStringInt2() { + container1.setOwner(4); + container2.setOwner(4); + container3.setOwner(6); + container4.setOwner(9); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("owner", 4).size(), 2); + assertEquals(containerDatabase.find("owner", 9).size(), 1); + } + + @Test + public void testFindStringInt3() { + container1.setOwner(4); + container2.setOwner(4); + container3.setOwner(6); + container4.setOwner(9); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("owner", 7).size(), 0); + } + + @Test + public void testFindStringInt4() { + container1.setContainerID(4); + container2.setContainerID(10); + container3.setContainerID(6); + container4.setContainerID(9); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("containerID", 10).size(), 1); + } + + @Test + public void testFindStringInt5() { + container1.setContainerID(4); + container2.setContainerID(10); + container3.setContainerID(6); + container4.setContainerID(9); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("containerID", 12).size(), 0); + } + + @Test + public void testFindStringInt6() { + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("owner", 4).size(), 0); + assertEquals(containerDatabase.find("containerID", 10).size(), 0); + } + + @Test + public void testFindStringString() { + container1.setPosition("Accra"); + container2.setPosition("Accra"); + container3.setPosition("Accra"); + container4.setPosition("Manchester"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find(null, "Manchester").size(), 0); + } + + @Test + public void testFindStringString2() { + container1.setPosition("Accra"); + container2.setPosition("Accra"); + container3.setPosition("Accra"); + container4.setPosition("Manchester"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("position", "mANCheSTer").size(), 1); + } + + @Test + public void testFindStringString3() { + container1.setPosition("Accra"); + container2.setPosition("Accra"); + container3.setPosition("Accra"); + container4.setPosition("Manchester"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("position", "Oslo").size(), 0); + } + + @Test + public void testFindStringString4() { + container1.setPosition("Accra"); + container2.setPosition("Accra"); + container4.setPosition("Manchester"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("position", "Accra").size(), 2); + } + + @Test + public void testFindStringString5() { + container1.setContentType("Oranges"); + container2.setContentType("Oranges"); + container3.setContentType("Peaches"); + container4.setContentType("Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("contentType", "oranges").size(), 2); + } + + @Test + public void testFindStringString6() { + container1.setContentType("Oranges"); + container2.setContentType("Oranges"); + container3.setContentType("Peaches"); + container4.setContentType("Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("contentType", "plums").size(), 0); + } + + @Test + public void testFindStringString7() { + container1.setContentType("Oranges"); + container3.setContentType("Peaches"); + container4.setContentType("Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("contentType", "peaches").size(), 1); + } + + @Test + public void testFindStringString8() { + container1.setCompany("Captain Orange"); + container2.setCompany("Captain Orange"); + container3.setCompany("Captain Peach"); + container4.setCompany("Captain Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("company", "captain orange").size(), 2); + } + + @Test + public void testFindStringString9() { + container1.setCompany("Captain Orange"); + container2.setCompany("Captain Orange"); + container3.setCompany("Captain Peach"); + container4.setCompany("Captain Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("company", "Captain Plum").size(), 0); + } + + @Test + public void testFindStringString10() { + container1.setCompany("Captain Orange"); + container2.setCompany("Captain Orange"); + container3.setCompany("Captain Peach"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("company", "Captain orange").size(), 2); + } + + @Test + public void testFindStringString11() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("CO11111"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("journeyID", "co11111").size(), 4); + } + + @Test + public void testFindStringString12() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("CO11111"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("journeyID", "MS8273").size(), 0); + } + + @Test + public void testFindStringString13() { + container3.setCurrentJourney("CO11111"); + container4.setCurrentJourney("CO11111"); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + System.out.println(containerDatabase.find("journeyID", "CO11111").size()); + assertEquals(containerDatabase.find("journeyID", "CO11111").size(), 2); + } + + @Test + public void testFindStringString14() { + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find("journeyID", "CO11111").size(), 0); + } + + + @Test + public void testFindBoolean() { + container1.setAvailability(true); + container2.setAvailability(true); + container3.setAvailability(true); + container4.setAvailability(false); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find(false).size(), 1); + } + + @Test + public void testFindBoolean2() { + containerDatabase.setContainers(containers); + + assertEquals(containerDatabase.find(false).size(), 0); + } + + @Test + public void testRegister() { + container1.setContainerID(4); + container2.setContainerID(6); + container3.setContainerID(9); + container4.setContainerID(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.register("Oslo"); + assertEquals(response.getErrorCode(),010); + assertEquals(containerDatabase.getContainers().get(4).getPosition(),"Oslo"); + assertEquals(containerDatabase.getContainers().get(4).getContainerID(), 11); + } + + @Test + public void testRegister2() { + container1.setContainerID(4); + container2.setContainerID(6); + container3.setContainerID(9); + container4.setContainerID(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.register(null); + assertEquals(response.getErrorCode(),162); + } + + @Test + public void testRegister3() { + containerDatabase.setContainers(containers); + + response = containerDatabase.register("Oslo"); + assertEquals(containerDatabase.getContainers().get(0).getContainerID(), 1); + } + + @Test + public void testUpdatePosition() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("CO11111"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CO11111", "Accra"); + assertEquals(response.getErrorCode(), 070); + } + + @Test + public void testUpdatePosition2() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CO11111", "Accra"); + assertEquals(response.getErrorCode(), 070); + assertNull(container3.getPosition()); + } + + @Test + public void testUpdatePosition3() { + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CO11111", "Accra"); + assertEquals(response.getErrorCode(), 110); + assertNull(container3.getPosition()); + } + + @Test + public void testUpdatePosition4() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CO11111", "Accra"); + assertEquals(response.getErrorCode(), 070); + assertNull(container3.getPosition()); + } + + @Test + public void testUpdatePosition5() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CH45111", "Accra"); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testMarkArrived() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("CO11111"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.markArrived("CO11111"); + assertEquals(response.getErrorCode(), 022); + } + + @Test + public void testMarkArrived2() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.markArrived("CO11111"); + assertEquals(response.getErrorCode(), 022); + assertNull(container3.getPosition()); + } + + @Test + public void testMarkArrived3() { + containerDatabase.setContainers(containers); + + response = containerDatabase.markArrived("CO11111"); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testMarkArrived4() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.markArrived("CH45111"); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testMarkArrived5() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.updatePosition("CO11111", "Accra"); + assertEquals(response.getErrorCode(), 070); + assertNull(container3.getPosition()); + } + + + @Test + public void testRemove() { + container1.setContainerID(4); + container2.setContainerID(6); + container3.setContainerID(9); + container4.setContainerID(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.remove(5); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testRemove2() { + containerDatabase.setContainers(containers); + + response = containerDatabase.remove(1); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testRemove3() { + container1.setContainerID(4); + container2.setContainerID(6); + container3.setContainerID(9); + container4.setContainerID(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + response = containerDatabase.remove(3); + assertEquals(response.getErrorCode(), 074); + } + + @Test + public void testGetColumnCount() { + assertEquals(containerDatabase.getColumnCount(),7); + } + + @Test + public void testGetRowCount() { + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + assertEquals(containerDatabase.getRowCount(),4); + } + + @Test + public void testGetValueAt() { + container1.setContainerID(4); + container2.setContainerID(6); + container3.setContainerID(9); + container4.setContainerID(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object ID = containerDatabase.getValueAt(0, 0); + assertEquals(ID, 4); + } + + @Test + public void testGetValueAt2() { + container1.setOwner(4); + container2.setOwner(6); + container3.setOwner(9); + container4.setOwner(10); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object owner = containerDatabase.getValueAt(0, 1); + assertEquals(owner, 4); + } + + @Test + public void testGetValueAt3() { + container1.setPosition("Accra"); + container2.setPosition("Accra"); + container3.setPosition("Accra"); + container4.setPosition("Manchester"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object position = containerDatabase.getValueAt(3, 2); + assertEquals(position, "Manchester"); + } + + @Test + public void testGetValueAt4() { + container1.setContentType("Oranges"); + container2.setContentType("Oranges"); + container3.setContentType("Peaches"); + container4.setContentType("Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object position = containerDatabase.getValueAt(2, 3); + assertEquals(position, "Peaches"); + } + + @Test + public void testGetValueAt5() { + container1.setCompany("Captain Orange"); + container2.setCompany("Captain Orange"); + container3.setCompany("Captain Peach"); + container4.setCompany("Captain Avocado"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object company = containerDatabase.getValueAt(2, 4); + assertEquals(company, "Captain Peach"); + } + + @Test + public void testGetValueAt6() { + container1.setAvailability(false); + container2.setAvailability(false); + container3.setAvailability(true); + container4.setAvailability(false); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object availability = containerDatabase.getValueAt(2, 5); + assertEquals(availability, true); + } + + @Test + public void testGetValueAt7() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object journey = containerDatabase.getValueAt(2, 6); + assertEquals(journey, "MS84275"); + } + + @Test + public void testGetValueAt8() { + container1.setCurrentJourney("CO11111"); + container2.setCurrentJourney("CO11111"); + container3.setCurrentJourney("MS84275"); + container4.setCurrentJourney("CO11111"); + containers.add(container1); + containers.add(container2); + containers.add(container3); + containers.add(container4); + containerDatabase.setContainers(containers); + + Object journey = containerDatabase.getValueAt(2, 10); + assertNull(journey); + } + + @Test + public void testGetColumnNameInt() { + String name = containerDatabase.getColumnName(0); + assertEquals(name, "Container ID"); + } + + @Test + public void testGetColumnNameInt2() { + String name = containerDatabase.getColumnName(1); + assertEquals(name, "Current User"); + } + + @Test + public void testGetColumnNameInt3() { + String name = containerDatabase.getColumnName(2); + assertEquals(name, "Position"); + } + + @Test + public void testGetColumnNameInt4() { + String name = containerDatabase.getColumnName(3); + assertEquals(name, "Content Type"); + } + + @Test + public void testGetColumnNameInt5() { + String name = containerDatabase.getColumnName(4); + assertEquals(name, "Company"); + } + + @Test + public void testGetColumnNameInt6() { + String name = containerDatabase.getColumnName(5); + assertEquals(name, "Availability"); + } + + @Test + public void testGetColumnNameInt7() { + String name = containerDatabase.getColumnName(6); + assertEquals(name, "Current Journey"); + } + + @Test + public void testGetColumnNameInt8() { + String name = containerDatabase.getColumnName(25); + assertNull(name); + } + +} diff --git a/System/src/test/java/ContainerTest.java b/System/src/test/java/ContainerTest.java new file mode 100644 index 0000000..dca8576 --- /dev/null +++ b/System/src/test/java/ContainerTest.java @@ -0,0 +1,262 @@ + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import management.Container; +import management.HistoryBook; + +public class ContainerTest { + + private Container container; + + @Before + public void setUp() { + container = new Container(); + } + + ////////////////// + + @Test + public void testGetDate() { + assertNull(container.getDate()); + container.setDate("12\\12\\1212"); + assertEquals("12\\12\\1212", container.getDate()); + + } + + @Test + public void testSetDate() { + container.setDate("13\\12\\1212"); + assertEquals("13\\12\\1212", container.getDate()); + } + + ////////////////// + + @Test + public void testGetContainerID() { + assertEquals(0, container.getContainerID()); + container.setContainerID(25); + assertEquals(25, container.getContainerID()); + } + + @Test + public void testSetContainerID() { + container.setContainerID(30); + assertEquals(30, container.getContainerID()); + } + + @Test + public void testGetOwner() { + assertEquals(0, container.getOwner()); + container.setOwner(1); + assertEquals(1, container.getOwner()); + } + + @Test + public void testSetOwner() { + container.setOwner(4); + assertEquals(4, container.getOwner()); + } + + @Test + public void testGetPosition() { + assertNull(container.getPosition()); + container.setPosition("Lagos"); + assertEquals("Lagos", container.getPosition()); + } + + @Test + public void testSetPosition() { + container.setPosition("Cyprus"); + assertEquals("Cyprus", container.getPosition()); + } + + @Test + public void testGetContentType() { + assertNull(container.getContentType()); + container.setContentType("Paper"); + assertEquals("Paper", container.getContentType()); + } + + @Test + public void testSetContentType() { + container.setContentType("Bamboo"); + assertEquals("Bamboo", container.getContentType()); + } + + @Test + public void testGetCompany() { + assertNull(container.getCompany()); + container.setCompany("Captain Metal"); + assertEquals("Captain Metal", container.getCompany()); + } + + @Test + public void testSetCompany() { + container.setCompany("Captain Plastic"); + assertEquals("Captain Plastic", container.getCompany()); + } + + @Test + public void testIsAvailability() { + assertFalse(container.isAvailability()); + container.setAvailability(true); + assertTrue(container.isAvailability()); + } + + @Test + public void testSetAvailability() { + container.setAvailability(true); + assertTrue(container.isAvailability()); + } + + @Test + public void testGetCurrentJourney() { + assertNull(container.getCurrentJourney()); + container.setCurrentJourney("C056842"); + assertEquals("C056842", container.getCurrentJourney()); + } + + @Test + public void testSetCurrentJourney() { + container.setCurrentJourney("OM83743"); + assertEquals("OM83743", container.getCurrentJourney()); + } + + @Test + public void testGetPressure() { + assertEquals(0, container.getPressure()); + container.setPressure(90); + assertEquals(90, container.getPressure()); + } + + @Test + public void testSetPressure() { + container.setPressure(110); + assertEquals(110, container.getPressure()); + } + + @Test + public void testGetHumidity() { + assertEquals(0, container.getHumidity()); + container.setHumidity(50); + assertEquals(50, container.getHumidity()); + } + + @Test + public void testSetHumidity() { + container.setHumidity(34); + assertEquals(34, container.getHumidity()); + } + + @Test + public void testGetTemperature() { + assertEquals(0, container.getTemperature()); + container.setTemperature(298); + assertEquals(298, container.getTemperature()); + } + + @Test + public void testSetTemperature() { + container.setTemperature(300); + assertEquals(300, container.getTemperature()); + } + + @Test + public void testGetHistory() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + +// System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[12\\12\\1212]", container.getHistory().show()[0][0].toString()); + + } + + @Test + public void testGetHistory1() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + + assertEquals("[1]", container.getHistory().show()[1][0].toString()); + + } + + @Test + public void testGetHistory2() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[1]", container.getHistory().show()[2][0].toString()); + + } + + @Test + public void testGetHistory3() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[1]", container.getHistory().show()[3][0].toString()); + + } + + @Test + public void testGetHistory4() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[Oslo]", container.getHistory().show()[4][0].toString()); + + } + + + +// @Test +// public void testSetHistory() { +// fail("Not yet implemented"); +// } + + @Test + public void testAppendHistory() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + + /// the 5 tests above are also testing append each time since without append working they would not work either + assertEquals("[Oslo]", container.getHistory().show()[4][0].toString()); + + + } + +} diff --git a/System/src/test/java/CucumberTest.java b/System/src/test/java/CucumberTest.java index 0aa2cd1..b15372f 100644 --- a/System/src/test/java/CucumberTest.java +++ b/System/src/test/java/CucumberTest.java @@ -1,5 +1,3 @@ - - import org.junit.runner.RunWith; import io.cucumber.junit.CucumberOptions; import io.cucumber.junit.Cucumber; diff --git a/System/src/test/java/HistoryBookTest.java b/System/src/test/java/HistoryBookTest.java new file mode 100644 index 0000000..6a8707e --- /dev/null +++ b/System/src/test/java/HistoryBookTest.java @@ -0,0 +1,128 @@ + + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import management.Container; + +public class HistoryBookTest { + + private Container container; + @Before + public void setUp() { + container = new Container(); + + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + container.appendHistory(); + } + + @Test + public void testShow() { +// container.setDate("12\\12\\1212"); +// container.setHumidity(1); +// container.setTemperature(1); +// container.setPressure(1); +// container.setPosition("Oslo"); +// container.appendHistory(); + + assertEquals("[1]", container.getHistory().show()[1][0].toString()); + } + @Test + public void testShow1() { +// container.setDate("12\\12\\1212"); +// container.setHumidity(1); +// container.setTemperature(1); +// container.setPressure(1); +// container.setPosition("Oslo"); +// container.appendHistory(); + + assertEquals("[12\\12\\1212]", container.getHistory().show()[0][0].toString()); + } + @Test + public void testShow2() { +// container.setDate("12\\12\\1212"); +// container.setHumidity(1); +// container.setTemperature(1); +// container.setPressure(1); +// container.setPosition("Oslo"); +// container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[1]", container.getHistory().show()[2][0].toString()); + + } + + @Test + public void testShow3() { +// container.setDate("12\\12\\1212"); +// container.setHumidity(1); +// container.setTemperature(1); +// container.setPressure(1); +// container.setPosition("Oslo"); +// container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[1]", container.getHistory().show()[3][0].toString()); + + } + + @Test + public void testShow4() { +// container.setDate("12\\12\\1212"); +// container.setHumidity(1); +// container.setTemperature(1); +// container.setPressure(1); +// container.setPosition("Oslo"); +// container.appendHistory(); + + //System.out.println(container.getHistory().show()[0][0].toString()); + + assertEquals("[Oslo]", container.getHistory().show()[4][0].toString()); + +// System.out.println(container.getHistory().showTable()[0][1]); + + } + + @Test + public void testShowTable() { + assertEquals("Oslo", container.getHistory().showTable()[0][4].toString()); + } + + @Test + public void testShowTable2() { + assertEquals(1, container.getHistory().showTable()[0][3]); + } + + @Test + public void testShowTable3() { + assertEquals(1, container.getHistory().showTable()[0][2]); + } + + @Test + public void testShowTable4() { + assertEquals(1, container.getHistory().showTable()[0][1]); + } + + @Test + public void testShowTable5() { + assertEquals("12\\12\\1212", container.getHistory().showTable()[0][0].toString()); + } + + @Test + public void testAdd() { + container.setPosition("Copenhagen"); + container.appendHistory(); + assertEquals("Oslo", container.getHistory().showTable()[0][4].toString()); + assertEquals("Copenhagen", container.getHistory().showTable()[1][4].toString()); + + } + +} diff --git a/System/src/test/java/JourneyDatabaseTest.java b/System/src/test/java/JourneyDatabaseTest.java new file mode 100644 index 0000000..9b1d81a --- /dev/null +++ b/System/src/test/java/JourneyDatabaseTest.java @@ -0,0 +1,661 @@ +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import management.Container; +import management.Journey; +import management.JourneyDatabase; +import response.ResponseObject; + +public class JourneyDatabaseTest { + + private JourneyDatabase journeys; + private ArrayList containers; + private Journey journey; + private Map> map; + private ResponseObject response; + + @Before + public void setUp() { + journey = new Journey(); + journeys = new JourneyDatabase(); + map = new HashMap>(); + + containers = new ArrayList(); + response = new ResponseObject(0, "New response object"); + } + + @Test + public void testGetJourneys() { + assertTrue(journeys.getJourneys().isEmpty()); + map.put(journey, containers); + journeys.setJourneys(map); + assertFalse(journeys.getJourneys().isEmpty()); + } + + @Test + public void testSetJourneys() { + map.put(journey, containers); + journeys.setJourneys(map); + assertEquals(journeys.getJourneys().size(),1); + } + + @Test + public void testCreate() { + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Journey has been created"); + assertEquals(response.getErrorCode(), 020); + } + + @Test + public void testCreate2() { + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Journey has been created"); + assertEquals(response.getErrorCode(), 020); + } + + @Test + public void testCreate3() { + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Necessary parameters are not entered"); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testCreate4() { + journey.setJourneyID("CO75934"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Necessary parameters are not entered"); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testCreate5() { + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Necessary parameters are not entered"); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testCreate6() { + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Necessary parameters are not entered"); + assertEquals(response.getErrorCode(), 210); + } + + @Test + public void testRegisterTo() { + response = journeys.registerTo("CO83746", "Copenhagen", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Container is not found"); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testRegisterTo2() { + Container container = new Container(); + container.setPosition("Copenhagen"); + containers.add(container); + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.registerTo("CO85763", "Copenhagen", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Container has been assigned to a journey"); + assertEquals(response.getErrorCode(), 014); + } + + @Test + public void testRegisterTo3() { + Container container = new Container(); + container.setPosition("Accra"); + containers.add(container); + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.registerTo("CO75934", "Copenhagen", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRegisterTo4() { + Container container = new Container(); + container.setPosition("Copenhagen"); + containers.add(container); + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.registerTo("CO75934", "Accra", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRegisterTo5() { + Container container = new Container(); + container.setPosition("Copenhagen"); + containers.add(container); + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.registerTo("CO75934", "Copenhagen", "Accra", containers); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRegisterTo6() { + Container container = new Container(); + container.setPosition("Copenhagen"); + containers.add(container); + journey.setJourneyID("CO75934"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.registerTo("CO75994", "Copenhagen", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRegisterTo7() { + Container container = new Container(); + containers.add(container); + container.setPosition("Accra"); + response = journeys.registerTo("CO75934", "Copenhagen", "Oslo", containers); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testUpdatePosition() { + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + journeys.getJourneys().put(journey, containers); + + response = journeys.updatePosition("CO85763", "Accra"); + assertEquals(response.getErrorMessage(), "Position has been updated"); + assertEquals(response.getErrorCode(), 070); + } + + @Test + public void testUpdatePosition2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + response = journeys.updatePosition("CO85763", "Accra"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testSetDeparture() { + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeys.create(journey); + response = journeys.setDeparture("CO85763","12/05/3032"); + assertEquals(response.getErrorMessage(), "Departure date has been set"); + assertEquals(response.getErrorCode(), 071); + } + + @Test + public void testSetDeparture2() { + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + response = journeys.setDeparture("CO99999","12/05/3032"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testSetDeparture3() { + response = journeys.setDeparture("CO99999","12/05/3032"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testMarkArrived() { + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + journeys.getJourneys().put(journey, containers); + response = journeys.markArrived("CO85763"); + assertEquals(response.getErrorMessage(), "Arrival date has been set"); + assertEquals(response.getErrorCode(), 072); + } + + @Test + public void testMarkArrived2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + response = journeys.markArrived("CO85763"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testComplete() { + journey.setJourneyID("CO85763"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + journeys.getJourneys().put(journey, containers); + + response = journeys.complete("CO85763"); + assertEquals(response.getErrorMessage(), "Journey has been completed and successfully removed"); + assertEquals(response.getErrorCode(), 021); + } + + @Test + public void testComplete2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setCurrentJourney("CO85763"); + containers.add(container); + response = journeys.markArrived("CO85763"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testComplete3() { + response = journeys.markArrived("CO85763"); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRemoveContainer() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setContainerID(12); + containers.add(container); + journeys.getJourneys().put(journey, containers); + + response = journeys.removeContainer("CO89999", 12); + assertEquals(response.getErrorMessage(), "Container has been successfully removed"); + assertEquals(response.getErrorCode(), 011); + } + + @Test + public void testRemoveContainer2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setContainerID(12); + containers.add(container); + response = journeys.removeContainer("CO89769", 12); + assertEquals(response.getErrorMessage(), "Journey is not found"); + assertEquals(response.getErrorCode(), 120); + } + + @Test + public void testRemoveContainer3() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setContainerID(12); + containers.add(container); + journeys.getJourneys().put(journey, containers); + + response = journeys.removeContainer("CO89999", 15); + assertEquals(response.getErrorMessage(), "Container is not found"); + assertEquals(response.getErrorCode(), 110); + } + + @Test + public void testExtract() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setOwner(12); + containers.add(container); + journeys.getJourneys().put(journey, containers); + + assertEquals(journeys.extract(12).size(), 1); + } + + @Test + public void testExtract2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journeys.create(journey); + Container container = new Container(); + container.setOwner(12); + containers.add(container); + assertEquals(journeys.extract(17).size(), 0); + } + + @Test + public void testFind() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + assertEquals(journeys.find("journeyID", "CO89999").size(), 1); + } + + @Test + public void testFind2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + assertEquals(journeys.find("origin", "Copenhagen").size(), 1); + } + + @Test + public void testFind3() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + Journey journey3 = new Journey(); + journey3.setJourneyID("AO80000"); + journey3.setOrigin("Accra"); + journey3.setDestination("Manchester"); + journey3.setDepartureDate("23/05/2020"); + journey3.setArrivalDate("29/05/2020"); + journeys.create(journey3); + assertEquals(journeys.find("destination", "oslo").size(), 2); + } + + @Test + public void testFind4() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + Journey journey3 = new Journey(); + journey3.setJourneyID("AO80001"); + journey3.setOrigin("Accra"); + journey3.setDestination("Oslo"); + journey3.setDepartureDate("20/05/2020"); + journey3.setArrivalDate("27/05/2020"); + journeys.create(journey3); + assertEquals(journeys.find("departureDate", "23/05/2020").size(), 2); + } + + @Test + public void testFind5() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + assertEquals(journeys.find("arrivalDate", "24/05/2020").size(), 1); + } + + @Test + public void testFind6() { + assertEquals(journeys.find("somethingElse", "23/05/2020").size(), 0); + } + + + @Test + public void testGetColumnCount() { + assertEquals(journeys.getColumnCount(), 5); + } + + @Test + public void testGetRowCount() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Journey journey2 = new Journey(); + journey2.setJourneyID("AO80000"); + journey2.setOrigin("Accra"); + journey2.setDestination("Oslo"); + journey2.setDepartureDate("23/05/2020"); + journey2.setArrivalDate("27/05/2020"); + journeys.create(journey2); + assertEquals(journeys.getRowCount(), 2); + } + + @Test + public void testGetColumnNameInt() { + String name = journeys.getColumnName(0); + assertEquals(name, "Journey ID"); + } + + @Test + public void testGetColumnNameInt2() { + String name = journeys.getColumnName(1); + assertEquals(name, "Origin"); + } + + @Test + public void testGetColumnNameInt3() { + String name = journeys.getColumnName(2); + assertEquals(name, "Destination"); + } + + @Test + public void testGetColumnNameInt4() { + String name = journeys.getColumnName(3); + assertEquals(name, "Departure"); + } + + @Test + public void testGetColumnNameInt5() { + String name = journeys.getColumnName(4); + assertEquals(name, "Arrival"); + } + + @Test + public void testGetColumnNameInt6() { + String name = journeys.getColumnName(9); + assertNull(name); + } + + @Test + public void testGetValueAt() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + + Object ID = journeys.getValueAt(0, 0); + assertEquals(ID, "CO89999"); + } + + @Test + public void testGetValueAt2() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + Object origin = journeys.getValueAt(0, 1); + assertEquals(origin, "Copenhagen"); + } + + @Test + public void testGetValueAt3() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + + Object destination = journeys.getValueAt(0, 2); + assertEquals(destination, "Oslo"); + } + + @Test + public void testGetValueAt4() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + + Object departure = journeys.getValueAt(0, 3); + assertEquals(departure, "23/05/2020"); + } + + @Test + public void testGetValueAt5() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + + Object arrival = journeys.getValueAt(0, 4); + assertEquals(arrival, "24/05/2020"); + } + + @Test + public void testGetValueAt6() { + journey.setJourneyID("CO89999"); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + journey.setDepartureDate("23/05/2020"); + journey.setArrivalDate("24/05/2020"); + journeys.create(journey); + + Object object = journeys.getValueAt(0, 7); + assertNull(object); + } + +} diff --git a/System/src/test/java/JourneyTest.java b/System/src/test/java/JourneyTest.java new file mode 100644 index 0000000..695fb1d --- /dev/null +++ b/System/src/test/java/JourneyTest.java @@ -0,0 +1,121 @@ + + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import management.Journey; +import management.JourneyDatabase; + +public class JourneyTest { + + private Journey journey; + + @Before + public void setUp() { + journey = new Journey(); + } + + @Test + public void testGetJourneyID() { + assertNull(journey.getJourneyID()); + journey.setJourneyID("CO23143"); + assertEquals("CO23143", journey.getJourneyID()); + } + + @Test + public void testSetJourneyID() { + journey.setJourneyID("CO22287"); + assertEquals("CO22287", journey.getJourneyID()); + } + + @Test + public void testGetOrigin() { + assertNull(journey.getOrigin()); + journey.setOrigin("Copenhagen"); + assertEquals("Copenhagen", journey.getOrigin()); + } + + @Test + public void testSetOrigin() { + journey.setOrigin("Nice"); + assertEquals("Nice", journey.getOrigin()); + } + + @Test + public void testGetDestination() { + assertNull(journey.getDestination()); + journey.setDestination("Accra"); + assertEquals("Accra", journey.getDestination()); + } + + @Test + public void testSetDestination() { + journey.setDestination("Istanbul"); + assertEquals("Istanbul", journey.getDestination()); + } + + @Test + public void testGetDepartureDate() { + assertNull(journey.getDepartureDate()); + journey.setDepartureDate("23/07/2030"); + assertEquals("23/07/2030", journey.getDepartureDate()); + } + + @Test + public void testSetDepartureDate() { + journey.setDepartureDate("23/07/2044"); + assertEquals("23/07/2044", journey.getDepartureDate()); + } + + @Test + public void testGetArrivalDate() { + assertNull(journey.getArrivalDate()); + journey.setArrivalDate("23/07/2030"); + assertEquals("23/07/2030", journey.getArrivalDate()); + } + + @Test + public void testSetArrivalDate() { + journey.setArrivalDate("23/07/2044"); + assertEquals("23/07/2044", journey.getArrivalDate()); + } + + @Test + public void testSetJourneyDatabase() { + JourneyDatabase journeyDatabase = new JourneyDatabase(); + assertNull(journey.getJourneyDatabase()); + journey.setJourneyDatabase(journeyDatabase); + assertNotNull(journey.getJourneyDatabase()); + } + + @Test + public void testCreateJourneyID() { + JourneyDatabase journeyDatabase = new JourneyDatabase(); + journey.setJourneyDatabase(journeyDatabase); + journey.setOrigin("Copenhagen"); + journey.setDestination("Oslo"); + assertNull(journey.getJourneyID()); + journey.createJourneyID(); + assertNotNull(journey.getJourneyID()); + } + + @Test + public void testCreateJourneyID2() { + JourneyDatabase journeys = new JourneyDatabase(); + Journey journey1 = new Journey(); + String journeyID1 = "CO23143"; + journey1.setJourneyID(journeyID1); + journeys.create(journey1); + + Journey journey2 = new Journey(); + journey2.setOrigin("Copenhagen"); + journey2.setDestination("Oslo"); + journey2.setJourneyDatabase(journeys); + assertNull(journey2.getJourneyID()); + journey2.createJourneyID(); + assertNotNull(journey2.getJourneyID()); + } + +} diff --git a/System/src/test/java/LogisticsCompanyTest.java b/System/src/test/java/LogisticsCompanyTest.java new file mode 100644 index 0000000..52abf0b --- /dev/null +++ b/System/src/test/java/LogisticsCompanyTest.java @@ -0,0 +1,285 @@ + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import io.cucumber.java.Before; +import management.Client; +import management.ClientDatabase; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.JourneyDatabase; +import management.LogisticsCompany; +import response.ResponseObject; + +public class LogisticsCompanyTest { + + private Client client; + private LogisticsCompany company; + + + @Before + public void createCompany() { + client = new Client("Alice", "Allinson", "21-04-2021", "Alice@mail.com", "0383747858"); + company = LogisticsCompany.getInstance(); + company.cleanDataBase(); + + + } + + @Test + public void getClientDatabaseandSetClientDatabase() { + company = LogisticsCompany.getInstance(); + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Javier" ,"Almendra", "21/04/2021", "Javier.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + + registery.setClients(clients); + company.setClientDatabase(registery); + + assertTrue(registery.equals(company.getClientDatabase())); + + } + + @Test + public void getContainerDatabaseandSetContainerDatabase() { + ContainerDatabase containers = new ContainerDatabase(); + company = LogisticsCompany.getInstance(); + int counter = 1; + for (int i = 1; i <= 10; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(counter - 1).setContainerID(counter); + containers.getContainers().get(counter - 1).setPosition("Copenhagen"); + containers.getContainers().get(counter - 1).setAvailability(true); + counter += 1; + } + company.setContainerDatabase(containers); + + assertNotNull(containers.equals(company.getContainerDatabase())); + } + + @Test + public void getJourneyDatabaseandSetJourneyDatabase() { + JourneyDatabase journeys = new JourneyDatabase(); + company = LogisticsCompany.getInstance(); + + Journey journey1 = new Journey(); + String journeyID1 = "CO23143"; + String origin1 = "Copenhagen"; + String destination1 = "Oslo"; + journey1.setJourneyID(journeyID1); + journey1.setOrigin(origin1); + journey1.setDestination(destination1); + journey1.setDepartureDate("21/04/2021"); + journey1.setArrivalDate("22/04/2021"); + journeys.create(journey1); + + Journey journey2 = new Journey(); + String journeyID2 = "AC21003"; + String origin2 = "Amsterdam"; + String destination2 = "Copenhagen"; + journey2.setJourneyID(journeyID2); + journey2.setOrigin(origin2); + journey2.setDestination(destination2); + journeys.create(journey2); + + company.setJourneyDatabase(journeys); + + assertTrue(journeys.equals(company.getJourneyDatabase())); + + + + } + + + @Test + public void testGetNameandSetName() { + company = LogisticsCompany.getInstance(); + company.setName("Maersk"); + assertTrue("Company name is not Maersk", "Maersk".equals(company.getName())); + } + + @Test + public void testGetClientDatabaseandSetClientDatabase() { + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + Client client2 = new Client("Javier" ,"Almendra", "21/04/2021", "Javier.Almendra@mail.com", "+999-999-99-999"); + client2.setId(100001); + clients.add(client2); + Client client3 = new Client("Kristyn" ,"Korboe", "21/04/2021", "Kristyn.Korboe@mail.com", "+999-999-99-999"); + client3.setId(100002); + clients.add(client3); + + registery.setClients(clients); + + assertNotNull(registery.getClients().size()); + + } + + + @Test + public void testCreateNewClient() throws Exception { + company = LogisticsCompany.getInstance(); + Client client1 = new Client(); + client1.setfirstName("Sarthak"); + client1.setlastName("Trehan"); + client1.setBirthDate("24-02-2021"); + client1.setEmail("alice@mail.com"); + client1.setId(1); + client1.setPhoneNumber("1234567"); + client1.setPassword("0000"); + + Client client2 = new Client(); + client2.setlastName("Allison"); + client2.setBirthDate("24-02-2021"); + client2.setEmail("alice@mail.com"); + client2.setId(1); + client2.setPhoneNumber("1234567"); + client2.setPassword("0000"); + + Client client3 = new Client(); + client3.setfirstName("Alice"); + client3.setBirthDate("24-02-2021"); + client3.setEmail("alice@mail.com"); + client3.setId(2); + client3.setPhoneNumber("1234567"); + client3.setPassword("0000"); + + Client client4 = new Client(); + client4.setfirstName("Alice"); + client4.setlastName("Allison"); + client4.setBirthDate("24-02-2021"); + client4.setEmail(null); + client4.setId(3); + client4.setPhoneNumber("1234567"); + client4.setPassword("0000"); + + Client client5 = new Client(); + client5.setfirstName("Alice"); + client5.setlastName("Allison"); + client5.setBirthDate("24-02-2021"); + client5.setEmail("alice1@mail.com"); + client5.setPhoneNumber(null); + client5.setId(4); + client5.setPassword("0000"); + + Client client6 = new Client(); + client6.setfirstName("Alice"); + client6.setlastName("Allison"); + client6.setBirthDate("24-02-2021"); + client6.setEmail(null); + client6.setPhoneNumber(null); + client6.setId(5); + client6.setPassword("0000"); + + Client client7 = new Client(); + client7.setfirstName("Alice"); + client7.setlastName("Allison"); + client7.setBirthDate("24-02-2021"); + client7.setEmail("alice12@mail.com"); + client7.setPhoneNumber("1234567"); + client7.setId(5); + client7.setPassword("0000"); + + Client client8 = new Client(); + client8.setfirstName("Alice"); + client8.setlastName("Allison"); + client8.setBirthDate("24-02-2021"); + client8.setEmail("alice@mail.com"); + client8.setPhoneNumber("123456799"); + client8.setId(5); + client8.setPassword("0000"); + + ResponseObject response = company.CreateNewClient(client1); + ResponseObject response1 = company.CreateNewClient(client2); + ResponseObject response2 = company.CreateNewClient(client3); + ResponseObject response3 = company.CreateNewClient(client4); + ResponseObject response4 = company.CreateNewClient(client5); + ResponseObject response5 = company.CreateNewClient(client6); + ResponseObject response6 = company.CreateNewClient(client7); + ResponseObject response7 = company.CreateNewClient(client8); + + assertTrue("client not created", response.getErrorCode() == 1000); + assertTrue("client not created", response1.getErrorCode() == 1001); + assertTrue("client not created", response2.getErrorCode() == 1001); + assertTrue("client not created", response5.getErrorCode() == 1002); + assertTrue("client not created", response3.getErrorCode() == 1002); + assertTrue("client not created", response4.getErrorCode() == 1002); + assertTrue("client not created", response6.getErrorCode() == 1003); + assertTrue("client not created", response7.getErrorCode() == 1003); + } + + @Test (expected = IndexOutOfBoundsException.class) + public void testGetClientInt() throws Exception { + client = new Client(); + company = LogisticsCompany.getInstance(); + client.setId(1); + client.setfirstName("Alice"); + + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + company.CreateNewClient(client); + assertTrue("not the correct client", client.getId() == company.getClientDatabase().getClient(1).get(0).getId()); + + + + } + + @Test (expected = NullPointerException.class) + public void testGetClientStringString() { + + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("Alan", "Mansour", "21/04/2021", "Alan.Mansour@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + + registery.setClients(clients); + + company = LogisticsCompany.getInstance(); + + + assertTrue("not the correct client", client1.getfirstName().equals(company.getClientDatabase().getClient("Alan", "Mansour").get(0).getfirstName()) & client.getlastName().equals(company.getClientDatabase().getClient("Alan", "Mansour").get(0).getlastName())); + } + + @Test (expected = IndexOutOfBoundsException.class) + public void testGetClientString() { + + ClientDatabase registery = new ClientDatabase(); + + ArrayList clients = new ArrayList(); + Client client1 = new Client("LOOO", "DOOOOr", "21/04/2021", "LOOO.DOOO@mail.com", "+999-999-99-998"); + client1.setId(100000); + client1.setPassword("0000"); + clients.add(client1); + + registery.setClients(clients); + + company = LogisticsCompany.getInstance(); + + + assertTrue("not the correct client", client1.getfirstName().equals(company.getClientDatabase().getClient("LOOO.DOOO@mail.com").get(0).getfirstName()) & client.getlastName().equals(company.getClientDatabase().getClient("LOOO.DOOO@mail.com").get(0).getlastName())); + + } + +} diff --git a/System/src/test/java/StepDefinitionClientUpdate.java b/System/src/test/java/StepDefinitionClientUpdate.java new file mode 100644 index 0000000..09cd74e --- /dev/null +++ b/System/src/test/java/StepDefinitionClientUpdate.java @@ -0,0 +1,112 @@ +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.LogisticsCompany; +import response.ResponseObject; + +import static org.junit.Assert.*; +import java.util.ArrayList; + +public class StepDefinitionClientUpdate { + + LogisticsCompany logisticsCompany = LogisticsCompany.getInstance(); + Client newClient = new Client(); + Client registeredClient = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + Client clientWithSameNameasRegisteredClient = new Client("Alice", "Allison", "999999","AliceAllison12@gmail.com" , "12345679"); + Client clientWithoutEmail; + Client clientWithoutPhoneNumber; + Client registeredClient2 = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + LogisticsCompany logisticscompany2; + Client unregisteredClient; + ArrayList theReturnedClientList; + ResponseObject response1; + ResponseObject response2; + + + //client update feature + //scenario 1: Successful update of all information except name and birth date + + @Given("registered client") + public void registered_client() throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(registeredClient2); + + } + + @When("the client wants to update all their information except their name and birth date") + public void the_client_wants_to_update_all_their_information_except_their_name_and_birth_date() throws Exception { + response1 = registeredClient2.updateInfo("Alice", "Allison", "01012000", "AliceAllison12@gmail.com", "12345679", logisticsCompany.getClientDatabase()); + } + + @Then("the informtion is updated successfully") + public void the_informtion_is_updated_successfully() { + assertTrue(response1.getErrorCode()==1004); + + } + //scenario 2: UnSuccessful update due to the client not being registered by the company + + @Given("unregistered client") + public void unregistered_client() { + logisticsCompany.cleanDataBase(); + + unregisteredClient = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + + } + + @When("the person wants to update all their information except their name and birth date") + public void the_person_wants_to_update_all_their_information_except_their_name_and_birth_date() throws Exception { + unregisteredClient.updateInfo("Alice","Allison","01012000" ,"AliceAllison12@gmail.com", "12345679", logisticsCompany.getClientDatabase()); + } + + @Then("the informtion is not updated successfully") + public void the_informtion_is_not_updated_successfully() { + assertFalse(logisticsCompany.getClientDatabase().checkUpdatedInfo("Alice", "Allison", "01012000", "AliceAllison12@gmail.com", "12345679")); + } + + //scenario 3: UnSuccessful update due to illegal phone number + + @Given("a phone number that exists in the system") + public void a_phone_number_that_exists_in_the_system() throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(new Client("Alice", "Bobbinson","01012000","AliceAllison12@gmail.com", "12345679")); + logisticsCompany.CreateNewClient(registeredClient2); + + + } + + @When("the client wants to update all their contact phone number to already existing phone number") + public void the_client_wants_to_update_all_their_contact_phone_number_to_already_existing_phone_number() throws Exception { + response1 = registeredClient2.updateInfo("Alice", "Allison","01012000", "AliceAllison@gmail.com", "12345679", logisticsCompany.getClientDatabase()); + } + + @Then("the informtion is not updated") + public void the_informtion_is_not_updated() { + assertTrue(response1.getErrorCode()== 1006); + + } + + //scenario 4: UnSuccessful update due to illegal email + + @Given("a email that exists in the system") + public void a_email_that_exists_in_the_system() throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(new Client("Alice", "Bobbinson","01012000" ,"AliceAllison12@gmail.com", "12345679")); + logisticsCompany.CreateNewClient(registeredClient2); + + } + + @When("the client wants to update all their contact phone number to already existing email") + public void the_client_wants_to_update_all_their_contact_phone_number_to_already_existing_email() throws Exception { + response1 = registeredClient2.updateInfo("Alice", "Allison","01012000" ,"AliceAllison12@gmail.com", "12345678", logisticsCompany.getClientDatabase()); + } + + @Then("the informtion is not updated version {int}") + public void the_informtion_is_not_updated_version(Integer int1) { + assertTrue(response1.getErrorCode()==1005); + } + +} \ No newline at end of file diff --git a/System/src/test/java/StepDefinitionContactClient.java b/System/src/test/java/StepDefinitionContactClient.java new file mode 100644 index 0000000..9fa3bda --- /dev/null +++ b/System/src/test/java/StepDefinitionContactClient.java @@ -0,0 +1,131 @@ +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.LogisticsCompany; +import response.ResponseObject; + +import static org.junit.Assert.*; +import java.util.ArrayList; + +public class StepDefinitionContactClient { + + LogisticsCompany logisticsCompany = LogisticsCompany.getInstance(); + Client newClient = new Client(); + Client registeredClient = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + Client clientWithSameNameasRegisteredClient = new Client("Alice", "Allison", "999999","AliceAllison12@gmail.com" , "12345679"); + Client clientWithoutEmail; + Client clientWithoutPhoneNumber; + Client registeredClient2 = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + LogisticsCompany logisticscompany2; + Client unregisteredClient; + ArrayList theReturnedClientList; + ResponseObject response1; + ResponseObject response2; + + + + // company get info of client feature: + + //scenario 1: Contacting registered client by unique id + + @Given("registered client2") + public void registered_client() throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(registeredClient2); + + } + + @When("the company searches for the client by id") + public void the_company_searches_for_the_client_by_id() { + + theReturnedClientList = logisticsCompany.getClientDatabase().getClient(1); + + } + + @Then("the company gets all the info of the client") + public void the_company_gets_all_the_info_of_the_client() { + + for (Client theReturnedClient : theReturnedClientList) { + assertTrue(theReturnedClient.getfirstName() == registeredClient2.getfirstName()); + assertTrue(theReturnedClient.getlastName() == registeredClient2.getlastName()); + assertTrue(theReturnedClient.getBirthDate() == registeredClient2.getBirthDate()); + assertTrue(theReturnedClient.getEmail() == registeredClient2.getEmail()); + assertTrue(theReturnedClient.getPhoneNumber() == registeredClient2.getPhoneNumber()); + assertTrue(theReturnedClient.getId() == registeredClient2.getId()); + } + } + + + //scenario 2: Contacting registered client by name + + @Given("atleast {int} registered clients with the same name") + public void atleast_registered_clients_with_the_same_name(Integer int1) throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(registeredClient); + logisticsCompany.CreateNewClient(registeredClient2); + + } + + @When("the company searches for the client by name") + public void the_company_searches_for_the_client_by_name() { + theReturnedClientList = logisticsCompany.getClientDatabase().getClient("Alice", "Allison"); + + + } + + @Then("the company gets all the info of the client of both clients") + public void the_company_gets_all_the_info_of_the_client_of_both_clients() { + for (Client theReturnedClient : theReturnedClientList) { + assertTrue(theReturnedClient.getfirstName() == registeredClient.getfirstName()); + assertTrue(theReturnedClient.getlastName() == registeredClient2.getlastName()); + assertTrue(theReturnedClient.getfirstName() == registeredClient2.getfirstName()); + assertTrue(theReturnedClient.getlastName() == registeredClient.getlastName()); + + } + + } + + //scenario 3: Contacting client by id that doesn't exists + @Given("a registery") + public void a_registery() throws Exception { + logisticsCompany.cleanDataBase(); + + logisticsCompany.CreateNewClient(registeredClient); + logisticsCompany.CreateNewClient(registeredClient2); + + + } + + @When("the company searches for the client by the non existing id") + public void the_company_searches_for_the_client_by_the_non_existing_id() { + theReturnedClientList = logisticsCompany.getClientDatabase().getClient(69); + + } + + @Then("the company does not get any info") + public void the_company_does_not_get_any_info() { + assertTrue(theReturnedClientList.isEmpty()); + + } + + + //scenario 4: Contacting client by name that doesn't exists + + + + @When("the company searches for the client by the non existing name") + public void the_company_searches_for_the_client_by_the_non_existing_name() { + theReturnedClientList = logisticsCompany.getClientDatabase().getClient("Dragon","Slayer"); + + } + + //Scenario 5: Contacting registered client by email + @When("the company searches for the client by email") + public void the_company_searches_for_the_client_by_email() { + theReturnedClientList = logisticsCompany.getClientDatabase().getClient("AliceAllison@gmail.com"); + } + +} \ No newline at end of file diff --git a/System/src/test/java/StepDefinitionContainerManagement.java b/System/src/test/java/StepDefinitionContainerManagement.java new file mode 100644 index 0000000..105982b --- /dev/null +++ b/System/src/test/java/StepDefinitionContainerManagement.java @@ -0,0 +1,262 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.LogisticsCompany; +import response.ResponseObject; + +public class StepDefinitionContainerManagement { + + Client client; + Container container; + Journey journey; + ResponseObject response; + + ContainerDatabase containers = new ContainerDatabase(); + ContainerDatabase myContainers = new ContainerDatabase(); + + String location; + String contentType; + String company; + int quantity; + + @Given("location {string}") + public void location(String location) { + this.location = location; + } + + @Given("content-type {string}") + public void content_type(String contentType) { + this.contentType = contentType; + } + + @Given("company {string}") + public void company(String company) { + this.company = company; + } + + @Given("number of containers {int}") + public void number_of_containers(int number) { + this.quantity = number; + } + + + @Given("shipping yard in {string} with {int} containers") + public void shipping_yard_with_containers(String position, Integer number) { + this.location = position; + for (int i = 1; i <= number; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(i - 1).setContainerID(i); + containers.getContainers().get(i - 1).setPosition(position); + containers.getContainers().get(i - 1).setAvailability(true); + } + } + + @When("booking") + public void booking() { + client = new Client(); + client.setId(1); + response = containers.book(client.getId(), location, contentType, company, quantity); + } + + @Then("confirm booking {string} {int}") + public void confirm_booking(String message, int code) throws Exception { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + for (Container container : containers.extract(client.getId())) { + assertEquals(container.getOwner(), this.client.getId()); + assertEquals(container.getPosition(), this.location); + assertEquals(container.getContentType(), this.contentType); + assertEquals(container.getCompany(), this.company); + } + } + + @Then("deny booking {string} {int}") + public void deny_booking(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @When("registering container") + public void registering_container() { + response = containers.register(location); + } + + @Then("confirm registration {string} {int}") + public void confirm_registration(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + assertTrue(!containers.getContainers().isEmpty()); + } + + @Then("deny registration {string} {int}") + public void deny_registration(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + assertTrue(containers.getContainers().isEmpty()); + } + + @Given("{int} containers registered by client {int} to journey {string} positioned in {string}") + public void containers_registered_by_client_to_journey_positioned_in(Integer quantity, Integer clientID, String journeyID, String position) { + + int size = containers.getContainers().size(); + + for (int i = 1 + size; i <= quantity + size; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(i - 1).setContainerID(i); + containers.getContainers().get(i - 1).setPosition(position); + containers.getContainers().get(i - 1).setAvailability(true); + } + + containers.book(clientID, position, "undefined", "undefined", quantity); + + for (Container container : containers.extract(clientID)) { + container.setCurrentJourney(journeyID); + } + + } + + @When("updating containers current position with current journey {string} to {string}") + public void updating_containers_current_position_with_current_journey_to(String journeyID, String position) { + response = containers.updatePosition(journeyID, position); + } + + @Then("confirm position updating {string} {int}") + public void confirm_position_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny position updating {string} {int}") + public void deny_position_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Given("{int} containers containing {string} registered by client {int} regulated by {string} to journey {string} positioned in {string}") + public void containers_containing_registered_by_client_regulated_by_to_journey_positioned_in(Integer quantity, String contentType, Integer clientID, String company, String journeyID, String position) { + + int size = containers.getContainers().size(); + + for (int i = 1 + size; i <= quantity + size; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(i - 1).setContainerID(i); + containers.getContainers().get(i - 1).setPosition(position); + containers.getContainers().get(i - 1).setAvailability(true); + } + + containers.book(clientID, position, contentType, company, quantity); + + for (Container container : containers.extract(clientID)) { + container.setCurrentJourney(journeyID); + } + + } + + @When("finding containers based on criteria {string} specified as {string}") + public void finding_containers_based_on_criteria_specified_as(String criteria, String entry) { + myContainers.setContainers(containers.find(criteria, entry)); + } + + @When("finding containers based on criteria {string} specified as {int}") + public void finding_containers_based_on_criteria_specified_as(String criteria, int entry) { + myContainers.setContainers(containers.find(criteria, entry)); + } + + @When("finding containers based on criteria {string} specified as false") + public void finding_containers_based_on_criteria_specified_as_false(String criteria) { + myContainers.setContainers(containers.find(false)); + } + + @Then("show containers with container-ID {int}") + public void show_containers_with_container_ID(int containerID) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getContainerID(), containerID); + } + } + + @Then("show containers with client-ID {int}") + public void show_containers_with_client_ID(int clientID) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getOwner(), clientID); + } + } + + @Then("show containers with position {string}") + public void show_containers_with_position(String position) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getPosition(), position); + } + } + + @Then("show containers with content-type {string}") + public void show_containers_with_content_type(String contentType) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getContentType(), contentType); + } + } + + @Then("show containers with company {string}") + public void show_containers_with_company(String company) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getCompany(), company); + } + } + + @Then("show containers with journey-ID {string}") + public void show_containers_with_journey_ID(String journeyID) { + for (Container container : myContainers.getContainers()) { + assertEquals(container.getCurrentJourney(), journeyID); + } + } + + @Then("show all occupied containers") + public void show_all_occupied_containers() { + for (Container container : myContainers.getContainers()) { + assertEquals(container.isAvailability(), false); + } + } + + @When("updating containers current journey label with current journey {string}") + public void updating_containers_current_journey_label_with_current_journey(String journeyID) { + response = containers.markArrived(journeyID); + } + + @Then("confirm journey label updating {string} {int}") + public void confirm_journey_label_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny journey label updating {string} {int}") + public void deny_journey_label_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Given("a container with ID {int}") + public void a_container_with_ID(int containerID) { + container = new Container(); + container.setContainerID(containerID); + containers.getContainers().add(container); + } + + @When("removing container number {int}") + public void removing_container_number(int row) { + containers.remove(row); + } + + @Then("confirm removing of a container with ID {int}") + public void confirm_removing_of_a_container_with_ID(Integer containerID) { + for (Container container : containers.getContainers()) { + assertTrue(container.getContainerID() != containerID); + } + } + +} diff --git a/System/src/test/java/StepDefinitionDatabase.java b/System/src/test/java/StepDefinitionDatabase.java new file mode 100644 index 0000000..415d626 --- /dev/null +++ b/System/src/test/java/StepDefinitionDatabase.java @@ -0,0 +1,119 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.ClientDatabase; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.JourneyDatabase; + +public class StepDefinitionDatabase { + + Client client; + Container container; + Journey journey; + + Boolean status; + + ClientDatabase clientDatabase = new ClientDatabase(); + ContainerDatabase containerDatabase = new ContainerDatabase(); + JourneyDatabase journeyDatabase = new JourneyDatabase(); + + @When("producing client, container and journey databases") + public void producing_client_journey_and_container_databases() throws Exception { + clientDatabase.produce(); + containerDatabase.produce(); + journeyDatabase.produce(); + } + + @Then("confirm producing") + public void confirm_producing() throws Exception { + clientDatabase.pull(); + containerDatabase.pull(); + journeyDatabase.pull(); + assertTrue(clientDatabase.getClients().isEmpty()); + assertTrue(containerDatabase.getContainers().isEmpty()); + assertTrue(journeyDatabase.getJourneys().isEmpty()); + } + + @Given("client, container and journey databases") + public void client_journey_and_container_databases() throws Exception { + clientDatabase.produce(); + clientDatabase.pull(); + containerDatabase.produce(); + containerDatabase.pull(); + journeyDatabase.produce(); + journeyDatabase.pull(); + } + + @Given("unsaved data") + public void unsaved_data() { + client = new Client(); + client.setId(100); + clientDatabase.getClients().add(client); + + container = new Container(); + containerDatabase.getContainers().add(container); + + journey = new Journey(); + journey.setJourneyID("XX00000"); + journey.setOrigin("undefined"); + journey.setDestination("undefined"); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + journeyDatabase.create(journey); + + containerDatabase.getContainers().get(0).setContainerID(100); + containerDatabase.getContainers().get(0).setPosition("undefined"); + containerDatabase.getContainers().get(0).setAvailability(true); + + containerDatabase.book(client.getId(), "undefined", "undefined", "undefined", 1); + journeyDatabase.registerTo(journey.getJourneyID(), "undefined", "undefined", containerDatabase.extract(client.getId())); + } + + @When("saving") + public void saving() throws Exception { + clientDatabase.push(); + containerDatabase.push(); + journeyDatabase.push(); + } + + @Then("confirm database updates") + public void confirm_database_updates() throws Exception { + clientDatabase.pull(); + containerDatabase.pull(); + journeyDatabase.pull(); + assertEquals(clientDatabase.getClients().get(0).getId(), 100); + assertEquals(containerDatabase.getContainers().get(0).getContainerID(), 100); + for (Journey journey : journeyDatabase.getJourneys().keySet()) { + assertEquals(journey.getJourneyID(), "XX00000"); + }; + } + + @When("pulling") + public void pulling() { + try { + Files.delete(Paths.get("client_database.json")); + Files.delete(Paths.get("container_database.json")); + Files.delete(Paths.get("journey_database.json")); + clientDatabase.pull(); + containerDatabase.pull(); + journeyDatabase.pull(); + } catch (Exception e) { + e.printStackTrace(); + status = true; + } + } + + @Then("fail") + public void fail() throws Exception { + assertTrue(status); + } +} diff --git a/System/src/test/java/StepDefinitionHistoryBook.java b/System/src/test/java/StepDefinitionHistoryBook.java new file mode 100644 index 0000000..03e47c7 --- /dev/null +++ b/System/src/test/java/StepDefinitionHistoryBook.java @@ -0,0 +1,145 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.Container; +//import management.LogisticCompany; +import management.LogisticsCompany; + +public class StepDefinitionHistoryBook { + + Container container; + LogisticsCompany logcom; + Client client; + + @Given("^a container with id (\\d+)$") + public void a_container_with_id(int id) { + container = new Container(); + container.setContainerID(id); + } + + @Given("^a logisitc company \"([^\"]*)\"$") + public void a_logisitc_company(String name) { + logcom = LogisticsCompany.getInstance(); + logcom.setName(name); + } + + @When("^logisitc company chooses the container with journey id (\\d+)$") + public void logisitc_company_chooses_the_container_with_journey_id(int id) { + for (int i = 0; i < logcom.getContainerDatabase().getContainers().size(); i++) { + + if (logcom.getContainerDatabase().getContainers().get(i).getContainerID() == id) { + + container = logcom.getContainerDatabase().getContainers().get(i); + } + } + } + + @When("^add Temperature (\\d+)$") + public void add_Temperature(int temp) { + + container.setTemperature(temp); + } + + @When("^add Humidity (\\d+)$") + public void add_Humidity(int humid) { + + + container.setHumidity(humid); + + } + + @When("^add Pressure (\\d+)$") + public void add_Pressure(int pres) { + + + container.setPressure(pres); + + } + + @When("^add Position \"([^\\\"]*)\"$") + public void add_Position(String pos) { + + + container.setPosition(pos); + + } + + @Then("^update container's values$") + public void update_container_s_values() { + container.appendHistory(); + } + + @When("^requesting to see info for container (\\d+)$") + public void requesting_to_see_info_for_container(int id) { + + if (container.getOwner() == client.getId()) { + container.getHistory(); + } else { + + System.out.println("This container does not belong to you"); + } + } + + @Then("^history of container is shown$") + public void history_of_container_is_shown() { + container.setDate("12\\12\\1212"); + container.setHumidity(1); + container.setTemperature(1); + container.setPressure(1); + container.setPosition("Oslo"); + + if (container.getOwner() == client.getId()) { + container.getHistory().show(); + container.getHistory().showTable(); + } else { + + System.out.println("This container does not belong to you"); + } + + } + + @Then("^show message: container does not exist$") + public void show_message_container_does_not_exist() { + System.out.println("This container does not exist!"); + } + + @Given("^a container with id (\\d+) and owner (\\d+)$") + public void a_container_with_id_and_owner(int id, int owner) { + + + container = new Container(); + container.setContainerID(id); + + + + container.setOwner(owner); + + container.appendHistory(); + + + } + + @Given("^a client with id (\\d+)$") + public void a_client_with_id(int id) { + client = new Client(); + client.setId(id); + } + + @Then("^history of container is not shown$") + public void history_of_container_is_not_shown() { + + if (container.getOwner() == client.getId()) { + container.getHistory().show(); + } else { + + System.out.println("This container does not belong to you"); + } + + } + + + +} \ No newline at end of file diff --git a/System/src/test/java/StepDefinitionJourneyManagement.java b/System/src/test/java/StepDefinitionJourneyManagement.java new file mode 100644 index 0000000..d759121 --- /dev/null +++ b/System/src/test/java/StepDefinitionJourneyManagement.java @@ -0,0 +1,312 @@ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.Container; +import management.ContainerDatabase; +import management.Journey; +import management.JourneyDatabase; +import response.ResponseObject; + +public class StepDefinitionJourneyManagement { + + Client client; + Journey journey; + ResponseObject response; + + JourneyDatabase journeys = new JourneyDatabase(); + JourneyDatabase myJourneys = new JourneyDatabase(); + ContainerDatabase containers = new ContainerDatabase(); + ContainerDatabase myContainers = new ContainerDatabase(); + + String journeyID; + String origin; + String destination; + String departureDate; + String arrivalDate; + String location; + String contentType; + String company; + int quantity; + + @Given("journey {string} from {string} to {string}") + public void journey_from_to(String journeyID, String origin, String destination) { + journey = new Journey(); + journey.setJourneyID(journeyID); + journey.setOrigin(origin); + journey.setDestination(destination); + journey.setDepartureDate("undefined"); + journey.setArrivalDate("undefined"); + response = journeys.create(journey); + assertEquals(response.getErrorMessage(), "Journey has been created"); + assertEquals(response.getErrorCode(), 020); + } + + @Given("{int} booked containers from {string}") + public void booked_containers_from(Integer number, String position) { + this.location = position; + for (int i = 1; i <= number; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(i - 1).setContainerID(i); + containers.getContainers().get(i - 1).setPosition(position); + containers.getContainers().get(i - 1).setAvailability(true); + } + client = new Client(); + containers.book(client.getId(), location, contentType, company, quantity); + } + + @Given("origin {string}") + public void origin(String origin) { + this.origin = origin; + } + + @Given("destination {string}") + public void destination(String destination) { + this.destination = destination; + } + + @Given("departure date {string}") + public void departure_date(String departureDate) { + this.departureDate = departureDate; + } + + @Given("arrival date {string}") + public void arrival_date(String arrivalDate) { + this.arrivalDate = arrivalDate; + } + + @When("registering to {string}") + public void registering_to(String journeyID) { + response = journeys.registerTo(journeyID, origin, destination, containers.extract(client.getId())); + } + + @Then("confirm registering {string} {int}") + public void confirm_registering(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny registering {string} {int}") + public void deny_registering(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Given("{int} containers registered by client {int} to journey {string} from {string} to {string} departing {string} and arriving {string}") + public void containers_registered_to_journey_by_client_from_to(Integer quantity, Integer clientID, String journeyID, String origin, String destination, String departureDate, String arrivalDate) { + journey = new Journey(); + journey.setJourneyID(journeyID); + journey.setOrigin(origin); + journey.setDestination(destination); + journey.setDepartureDate(departureDate); + journey.setArrivalDate(arrivalDate); + journeys.create(journey); + + int size = containers.getContainers().size(); + + for (int i = 1 + size; i <= quantity + size; i++) { + containers.getContainers().add(new Container()); + containers.getContainers().get(i - 1).setContainerID(i); + containers.getContainers().get(i - 1).setPosition(origin); + containers.getContainers().get(i - 1).setAvailability(true); + } + + containers.book(clientID, origin, "undefined", "undefined", quantity); + journeys.registerTo(journeyID, origin, destination, containers.extract(clientID)); + } + + @When("updating containers current position of journey {string} to {string}") + public void updating_containers_current_position_of_journey_to(String journeyID, String position) { + response = journeys.updatePosition(journeyID, position); + } + + @Then("confirm updating {string} {int}") + public void confirm_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny updating {string} {int}") + public void deny_updating(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @When("finding based on criteria {string} specified as {string} for client {int}") + public void finding_based_on_criteria_specified_as_for_client(String criteria, String entry, int clientID) throws Exception { + myJourneys.setJourneys(journeys.extract(clientID)); + myJourneys.setJourneys(myJourneys.find(criteria, entry)); + } + + @Then("show journeys with journey-ID {string} of client {int}") + public void show_journeys_with_journeyID_owned_by_client(String journeyID, int clientID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getJourneyID(), journeyID); + for (Container contianer : myJourneys.getJourneys().get(key)) { + assertEquals(contianer.getOwner(), clientID); + } + } + } + + @Then("show journeys with origin {string} of client {int}") + public void show_journeys_with_origin_owned_by_client(String origin, int clientID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getOrigin(), origin); + for (Container contianer : myJourneys.getJourneys().get(key)) { + assertEquals(contianer.getOwner(), clientID); + } + } + } + + @Then("show journeys with destination {string} of client {int}") + public void show_journeys_with_destination_of_client(String destination, int clientID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getDestination(), destination); + for (Container contianer : myJourneys.getJourneys().get(key)) { + assertEquals(contianer.getOwner(), clientID); + } + } + } + + @Then("show journeys with departure date {string} of client {int}") + public void show_journeys_with_departure_date_of_client(String departureDate, int clientID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getDepartureDate(), departureDate); + for (Container contianer : myJourneys.getJourneys().get(key)) { + assertEquals(contianer.getOwner(), clientID); + } + } + } + + @Then("show journeys with arrival date {string} of client {int}") + public void show_journeys_with_arrival_date(String arrivalDate, int clientID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getArrivalDate(), arrivalDate); + for (Container contianer : myJourneys.getJourneys().get(key)) { + assertEquals(contianer.getOwner(), clientID); + } + } + } + + @When("finding based on criteria {string} specified as {string}") + public void finding_based_on_criteria_specified_as(String criteria, String entry) throws Exception { + myJourneys.setJourneys(journeys.find(criteria, entry)); + } + + @Then("show journeys with journey-ID {string}") + public void show_journeys_with_journeyID(String journeyID) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getJourneyID(), journeyID); + } + } + + @Then("show journeys with origin {string}") + public void show_journeys_with_origin(String origin) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getOrigin(), origin); + } + } + + @Then("show journeys with destination {string}") + public void show_journeys_with_destination(String destination) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getDestination(), destination); + } + } + + @Then("show journeys with departure date {string}") + public void show_journeys_with_departure_date(String departureDate) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getDepartureDate(), departureDate); + } + } + + @Then("show journeys with arrival date {string}") + public void show_journeys_with_arrival_date(String arrivalDate) { + for (Journey key : myJourneys.getJourneys().keySet()) { + assertEquals(key.getArrivalDate(), arrivalDate); + } + } + + @When("creating journey") + public void creating_journey() { + journey = new Journey(); + journey.setJourneyDatabase(journeys); + journey.setOrigin(origin); + journey.setDestination(destination); + journey.setDepartureDate(departureDate); + journey.setArrivalDate(arrivalDate); + response = journeys.create(journey); + } + + @Then("confirm journey creation {string} {int}") + public void confirm_journey_creation(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("assign a journey-ID") + public void assign_a_journeyID() { + journey.createJourneyID(); + for (Journey journey : journeys.getJourneys().keySet()) { + assertEquals(journey.getJourneyID().substring(0,2), String.format("%c%c", journey.getJourneyID().charAt(0), journey.getJourneyID().charAt(1))); + assertTrue(journey.getJourneyID().matches("[A-Z]{1}\\w{2}\\d{4}")); + } + } + + @Then("deny journey creation {string} {int}") + public void deny_journey_creation(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + + @When("updating current departure date of journey {string} to {string}") + public void updating_current_departure_date_of_journey_to(String journeyID, String departureDate) { + response = journeys.setDeparture(journeyID, departureDate); + } + + @When("updating current arrival date of journey {string} to todays date and setting the current journey label of containers to arrived") + public void updating_current_arrival_date_of_journey_to_todays_date_and_setting_the_current_journey_label_of_containers_to_arrived(String journeyID) { + response = journeys.markArrived(journeyID); + } + + @When("completing journey {string}") + public void completing_journey(String journeyID) { + response = journeys.complete(journeyID); + } + + @Then("confirm completing and removing of the journey {string} {int}") + public void confirm_completing_and_removing_of_the_journey(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny completing {string} {int}") + public void deny_completing(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @When("removing a container with ID {int} from journey {string}") + public void removing_a_container_with_ID_from_journey(Integer containerID, String journeyID) { + response = journeys.removeContainer(journeyID, containerID); + System.out.println(response.getErrorMessage()); + } + + @Then("confirm container removing {string} {int}") + public void confirm_container_removing(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + + @Then("deny container removing {string} {int}") + public void deny_container_removing(String message, int code) { + assertEquals(response.getErrorMessage(), message); + assertEquals(response.getErrorCode(), code); + } + +} diff --git a/System/src/test/java/StepDefinitionM1.java b/System/src/test/java/StepDefinitionM1.java deleted file mode 100644 index 02cd88e..0000000 --- a/System/src/test/java/StepDefinitionM1.java +++ /dev/null @@ -1,379 +0,0 @@ -import clientsManagement.Client; -import clientsManagement.Registery; -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; - -import static org.junit.Assert.*; - -import java.util.ArrayList; - - - -public class StepDefinitionM1 { - - Client newClient = new Client(); - Registery newRegister = new Registery(); - Client registeredClient = new Client("Alice Allison",01012000 ,"AliceAllison@gmail.com", 12345678); - Client clientWithSameNameasRegisteredClient = new Client("Alice Allison", 01012001,"AliceAllison12@gmail.com" , 12345679); - Client clientWithoutEmail; - Client clientWithoutPhoneNumber; - Client registeredClient2 = new Client("Alice Allison",01012000 ,"AliceAllison@gmail.com", 12345678, "Bobby Blue" , "BORDVEJ 26"); - Client unregisteredClient; - ArrayList theReturnedClientList; - - - //M1 feature 1 scenario 2 - - - @Given("a new client with name {string}") - public void a_new_client_with_name(String name) { - // Write code here that turns the phrase above into concrete actions - newClient.setName("Alice Allison"); - } - - @Given("born {int}") - public void born(Integer BirthDate) { - // Write code here that turns the phrase above into concrete actions - newClient.setBirthDate(BirthDate); - } - - @Given("with email {string}") - public void with_email(String email) { - // Write code here that turns the phrase above into concrete actions - newClient.setEmail(email); - } - - @Given("with phone number {int}") - public void with_phone_number(Integer PhoneNumber) { - // Write code here that turns the phrase above into concrete actions - newClient.setPhoneNumber(PhoneNumber); - } - - @When("the company registers the client") - public void the_company_registers_the_client() { - - - - newRegister.addClient(newClient); - - // Write code here that turns the phrase above into concrete actions - - } - @Then("the client is registered in the system successfully") - public void the_client_is_registered_in_the_system_successfully() { - // Write code here that turns the phrase above into concrete actions - - assertTrue(newRegister.ClientExists(newClient)); - } - - - - - @Then("the client is assigned a unique company ID {int}") - public void the_client_is_assigned_a_unique_company_ID(Integer id) { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkID(newClient)); - - } - //M1 feature 1 scenario 2 - @Given("a registered client") - public void a_registered_client() { - newRegister.addClient(registeredClient); - - // Write code here that turns the phrase above into concrete actions - - } - - @When("the registered client tries to register again") - public void the_registered_client_tries_to_register_again() { - newRegister.addClient(registeredClient); - - } - - @Then("the client is not registered in the system again") - public void the_client_is_not_registered_in_the_system_again() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkContactInfoOfClients(registeredClient) == 1); - - } - - //scenario 3 - - - @Given("an already registered client") - public void an_already_registered_client() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(registeredClient); - } - - @When("a new client registers with the same name but different contact info") - public void a_new_client_registers_with_the_same_name_but_different_contact_info() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(clientWithSameNameasRegisteredClient); - } - - @Then("the new client is registered in the system successfully") - public void the_new_client_is_registered_in_the_system_successfully() { - // Write code here that turns the phrase above into concrete actions - newRegister.ClientExists(registeredClient); - newRegister.ClientExists(clientWithSameNameasRegisteredClient); - - } - - @Then("both clients have different unique company IDs") - public void both_clients_have_different_unique_company_IDs() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkID(registeredClient)); - assertTrue(newRegister.checkID(clientWithSameNameasRegisteredClient)); - - } - - //Scenario 4: - - @Given("a client without a name") - public void a_client_without_a_name() { - // Write code here that turns the phrase above into concrete actions - - } - - @When("they try to regsiter without a name") - public void they_try_to_regsiter_without_a_name() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(newClient); - } - - @Then("then the client is not registered in the system") - public void then_the_client_is_not_registered_in_the_system() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkInstancesofClientinRegistery(newClient) == 0); - } - //scenario 5: - - @Given("a client with all info except email") - public void a_client_with_all_info_except_email() { - // Write code here that turns the phrase above into concrete actions - clientWithoutEmail = new Client("Alice Allison", 01012001 , 1234578); - - - - - } - - @When("they try to regsiter without an email") - public void they_try_to_regsiter_without_an_email() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(clientWithoutEmail); - } - - @Then("then the client is registered in the system successfully") - public void then_the_client_is_registered_in_the_system_successfully() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkInstancesofClientinRegistery(clientWithoutEmail) == 1); - } -//sceanrio 6: - - @Given("a client with all info except phone number") - public void a_client_with_all_info_except_phone_number() { - // Write code here that turns the phrase above into concrete actions - clientWithoutPhoneNumber = new Client("Alice Allison", 01012001, "AliceAllison12@gmail.com"); - } - - @When("they try to regsiter without an phone number") - public void they_try_to_regsiter_without_an_phone_number() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(clientWithoutPhoneNumber); - - } - - @Then("then the client without the phone numver is registered in the system successfully") - public void then_the_client_without_the_phone_numver_is_registered_in_the_system_successfully() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkInstancesofClientinRegistery(clientWithoutPhoneNumber) == 1); - - } - - //client update feature - //scenario 1: - - @Given("registered client") - public void registered_client() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(registeredClient2); - } - - @When("the client wants to update all their information except their name and birth date") - public void the_client_wants_to_update_all_their_information_except_their_name_and_birth_date() { - // Write code here that turns the phrase above into concrete actions - registeredClient2.update("AliceAllison12@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38", newRegister); - } - - @Then("the informtion is updated successfully") - public void the_informtion_is_updated_successfully() { - // Write code here that turns the phrase above into concrete actions - assertTrue(newRegister.checkUpdatedInfo("Alice Allison", 01012000, "AliceAllison12@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38")); - - } - //scenario 2: - - @Given("unregistered client") - public void unregistered_client() { - // Write code here that turns the phrase above into concrete actions - unregisteredClient = new Client("Alice Allison",01012000 ,"AliceAllison@gmail.com", 12345678, "Bobby Blue" , "BORDVEJ 26"); - - } - - @When("the person wants to update all their information except their name and birth date") - public void the_person_wants_to_update_all_their_information_except_their_name_and_birth_date() { - // Write code here that turns the phrase above into concrete actions - unregisteredClient.update("AliceAllison12@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38", newRegister); - } - - @Then("the informtion is not updated successfully") - public void the_informtion_is_not_updated_successfully() { - // Write code here that turns the phrase above into concrete actions - assertFalse(newRegister.checkUpdatedInfo("Alice Allison", 01012000, "AliceAllison12@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38")); - } - - //scenario 3: - - @Given("a phone number that exists in the system") - public void a_phone_number_that_exists_in_the_system() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(new Client("Alice Bobbinson",01012000 ,"AliceAllison12@gmail.com", 12345679, "Bobby Blue" , "BORDVEJ 26")); - - } - - @When("the client wants to update all their contact phone number to already existing phone number") - public void the_client_wants_to_update_all_their_contact_phone_number_to_already_existing_phone_number() { - // Write code here that turns the phrase above into concrete actions - registeredClient2.update("AliceAllison@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38", newRegister); - } - - @Then("the informtion is not updated") - public void the_informtion_is_not_updated() { - // Write code here that turns the phrase above into concrete actions - assertFalse(newRegister.checkUpdatedInfo("Alice Allison",01012000 ,"AliceAllison@gmail.com", 12345679, "Bobby Blue Moon" , "BORDVEJ 38")); - - } - - //scenario 4: - - @Given("a email that exists in the system") - public void a_email_that_exists_in_the_system() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(new Client("Alice Bobbinson",01012000 ,"AliceAllison12@gmail.com", 12345679, "Bobby Blue" , "BORDVEJ 26")); - } - - @When("the client wants to update all their contact phone number to already existing email") - public void the_client_wants_to_update_all_their_contact_phone_number_to_already_existing_email() { - // Write code here that turns the phrase above into concrete actions - registeredClient2.update("AliceAllison12@gmail.com", 12345678, "Bobby Blue Moon" , "BORDVEJ 38", newRegister); - } - - @Then("the informtion is not updated version {int}") - public void the_informtion_is_not_updated_version(Integer int1) { - // Write code here that turns the phrase above into concrete actions - assertFalse(newRegister.checkUpdatedInfo("Alice Allison",01012000 ,"AliceAllison12@gmail.com", 12345678, "Bobby Blue Moon " , "BORDVEJ 38")); - } - - - -// company get info of client feature: - - //scenario 1: - - - @When("the company searches for the client by id") - public void the_company_searches_for_the_client_by_id() { - // Write code here that turns the phrase above into concrete actions - theReturnedClientList = newRegister.getInfoClientbyId(1); - - } - - @Then("the company gets all the info of the client") - public void the_company_gets_all_the_info_of_the_client() { - - for (Client theReturnedClient : theReturnedClientList) { - // Write code here that turns the phrase above into concrete actions - assertTrue(theReturnedClient.getName() == registeredClient2.getName()); - assertTrue(theReturnedClient.getAddress() == registeredClient2.getAddress()); - assertTrue(theReturnedClient.getBirthDate() == registeredClient2.getBirthDate()); - assertTrue(theReturnedClient.getReferencePerson() == registeredClient2.getReferencePerson()); - assertTrue(theReturnedClient.getEmail() == registeredClient2.getEmail()); - assertTrue(theReturnedClient.getPhoneNumber() == registeredClient2.getPhoneNumber()); - assertTrue(theReturnedClient.getId() == registeredClient2.getId()); - } - } - - -//scenario 2: - - @Given("atleast {int} registered clients with the same name") - public void atleast_registered_clients_with_the_same_name(Integer int1) { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(registeredClient); - newRegister.addClient(registeredClient2); - } - - @When("the company searches for the client by name") - public void the_company_searches_for_the_client_by_name() { - // Write code here that turns the phrase above into concrete actions - theReturnedClientList = newRegister.getInfoClientbyName("Alice Allison"); - - - } - - @Then("the company gets all the info of the client of both clients") - public void the_company_gets_all_the_info_of_the_client_of_both_clients() { - // Write code here that turns the phrase above into concrete actions - for (Client theReturnedClient : theReturnedClientList) { - // Write code here that turns the phrase above into concrete actions - assertTrue(theReturnedClient.getName() == registeredClient.getName()); - assertTrue(theReturnedClient.getName() == registeredClient2.getName()); - - } - - } - - //scenario 3: - @Given("a registery") - public void a_registery() { - // Write code here that turns the phrase above into concrete actions - newRegister.addClient(registeredClient); - newRegister.addClient(registeredClient2); - - } - - @When("the company searches for the client by the non existing id") - public void the_company_searches_for_the_client_by_the_non_existing_id() { - // Write code here that turns the phrase above into concrete actions - theReturnedClientList = newRegister.getInfoClientbyId(69); - - } - - @Then("the company does not get any info") - public void the_company_does_not_get_any_info() { - // Write code here that turns the phrase above into concrete actions - assertTrue(theReturnedClientList.isEmpty()); - - } - - - //scenario 4: - - - - @When("the company searches for the client by the non existing name") - public void the_company_searches_for_the_client_by_the_non_existing_name() { - // Write code here that turns the phrase above into concrete actions - theReturnedClientList = newRegister.getInfoClientbyName("DragonSlayer69"); - } - - - - - - } - - diff --git a/System/src/test/java/StepDefinitionM2.java b/System/src/test/java/StepDefinitionM2.java deleted file mode 100644 index 193f7a0..0000000 --- a/System/src/test/java/StepDefinitionM2.java +++ /dev/null @@ -1,304 +0,0 @@ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Map; - -import io.cucumber.java.en.Given; -import io.cucumber.java.en.Then; -import io.cucumber.java.en.When; -import clientsManagement.Client; -import journeysManagement.Company; -import journeysManagement.Container; -import journeysManagement.ContainerDatabase; -import journeysManagement.Journey; -import journeysManagement.JourneyDatabase; -import journeysManagement.ResponseObject; - -public class StepDefinitionM2 { - - Client client; - Company logisticCompany; - Journey journey; - Map myContainers; - ResponseObject response; - - JourneyDatabase journeys = new JourneyDatabase(); - ContainerDatabase containers = new ContainerDatabase(); - - String journeyID; - String origin; - String destination; - String location; - String contentType; - String company; - int quantity; - - @Given("location {string}") - public void location(String location) { - this.location = location; - } - - @Given("content-type {string}") - public void content_type(String contentType) { - this.contentType = contentType; - } - - @Given("company {string}") - public void company(String company) { - this.company = company; - } - - @Given("number of containers {int}") - public void number_of_containers(int number) { - this.quantity = number; - } - - - @Given("shipping yard in {string} with {int} containers") - public void shipping_yard_with_containers(String position, Integer number) { - this.location = position; - for (int i = 1; i <= number; i++) { - containers.getContainers().add(new Container()); - containers.getContainers().get(i - 1).setContainerID(i); - containers.getContainers().get(i - 1).setPosition(position); - containers.getContainers().get(i - 1).setAvailability(true); - } - } - - @When("registering") - public void registering() { - client = new Client(); - response = client.registerContainers(location, contentType, company, quantity, containers); - for (Container container : client.getMyContainers()) { - assertEquals(container.getOwner(), this.client.getId()); - assertEquals(container.getPosition(), this.location); - assertEquals(container.getContentType(), this.contentType); - assertEquals(container.getCompany(), this.company); - } - } - - @Given("journey {string} from {string} to {string}") - public void journey_from_to(String journeyID, String origin, String destination) { - journey = new Journey(); - journey.setJourneyID(journeyID); - journey.setOrigin(origin); - journey.setDestination(destination); - response = journeys.create(journey); - assertEquals(response.getErrorMessage(), "Journey has been created"); - assertEquals(response.getErrorCode(), 012); - - } - - @Given("origin {string}") - public void origin(String origin) { - this.origin = origin; - } - - @Given("destination {string}") - public void destination(String destination) { - this.destination = destination; - } - - @Given("{int} registered containers from {string}") - public void registered_containers_from(Integer number, String position) { - this.location = position; - for (int i = 1; i <= number; i++) { - containers.getContainers().add(new Container()); - containers.getContainers().get(i - 1).setContainerID(i); - containers.getContainers().get(i - 1).setPosition(position); - containers.getContainers().get(i - 1).setAvailability(true); - } - client = new Client(); - client.registerContainers(position, "undefined", "undefined", number, containers); - } - - @When("registering to {string}") - public void registering_to(String journeyID) { - response = journeys.registerTo(journeyID, origin, destination, client.getMyContainers()); - } - - @Then("confirm registering {string} {int}") - public void confirm_registering(String message, int code) { - assertEquals(response.getErrorMessage(), message); - assertEquals(response.getErrorCode(), code); - } - - @Then("deny registering {string} {int}") - public void deny_registering(String message, int code) { - assertEquals(response.getErrorMessage(), message); - assertEquals(response.getErrorCode(), code); - } - - -// @Then("create journey-ID {string}") -// public void create_journey_ID(String journeyID) { -// journey.createJourneyID(); -// assertEquals(journey.getJourneyID().substring(0,2), String.format("%c%c", journeyID.charAt(0), journeyID.charAt(1))); -// assertTrue(journey.getJourneyID().matches("[A-Z]{1}\\w{2}\\d{4}")); -// } -// -// @Then("put on record") -// public void put_on_record() { -// response = journeys.upload(journey.getJourneyID(), container); -// assertEquals(response.getErrorMessage(), "Journey has been uploaded"); -// assertEquals(response.getErrorCode(), 012); -// assertEquals(journeys.getRecord().get(journey.getJourneyID()), container); -// } - - @Given("{int} containers registered to journey {string} from {string} to {string} regulated by {string}") - public void containers_registered_to_journey_from_to_regulated_by(Integer quantity, String journeyID, String origin, String destination, String company) { - journey = new Journey(); - journey.setJourneyID(journeyID); - journey.setOrigin(origin); - journey.setDestination(destination); - journeys.create(journey); - - for (int i = 1; i <= quantity; i++) { - containers.getContainers().add(new Container()); - containers.getContainers().get(i - 1).setContainerID(i); - containers.getContainers().get(i - 1).setPosition(origin); - containers.getContainers().get(i - 1).setAvailability(true); - } - client = new Client(); - client.registerContainers(origin, "undefined", company, quantity, containers); - journeys.registerTo(journeyID, origin, destination, client.getMyContainers()); - } - - @Given("logistic company {string}") - public void logistic_company(String company) { - logisticCompany = new Company(); - logisticCompany.setName(company); - } - - @When("updating containers current position of journey {string} to {string}") - public void updating_containers_current_position_of_journey_to(String journeyID, String position) { - response = logisticCompany.updatePosition(journeyID, position, journeys); - this.location = position; - } - - @Then("confirm updating {string} {int}") - public void confirm_updating(String message, int code) { - assertEquals(response.getErrorMessage(), message); - assertEquals(response.getErrorCode(), code); - } - - @Then("deny updating {string} {int}") - public void deny_updating(String message, int code) { - assertEquals(response.getErrorMessage(), message); - assertEquals(response.getErrorCode(), code); - } - - @Given("{int} containers containing {string} registered to journey {string} by client {int} from {string} to {string} regulated by {string}") - public void containers_containing_registered_to_journey_by_client_from_to_regulated_by(int quantity, String contentType, String journeyID, int clientID, String origin, String destination, String company) { - try { - journeys.pull(); - } catch (Exception e) { - - e.printStackTrace(); - } - - journey = new Journey(); - journey.setJourneyID(journeyID); - journey.setOrigin(origin); - journey.setDestination(destination); - journeys.create(journey); - - int size = containers.getContainers().size(); - - for (int i = 1 + size ; i <= quantity + size; i++) { - containers.getContainers().add(new Container()); - containers.getContainers().get(i - 1).setContainerID(i); - containers.getContainers().get(i - 1).setPosition(origin); - containers.getContainers().get(i - 1).setAvailability(true); - } - - client = new Client(); - client.setId(clientID); - client.registerContainers(origin, contentType, company, quantity, containers); - - journeys.registerTo(journeyID, origin, destination, client.getMyContainers()); - - try { - journeys.push(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @When("finding based on criteria {string} specified as {string} for client {int}") - public void finding_based_on_criteria_specified_as_for_client(String criteria, String entry, int clientID) { - try { - journeys.pull(); - } catch (Exception e) { - e.printStackTrace(); - } - myContainers = journeys.find(clientID, criteria, entry); - try { - journeys.produce(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Then("show journeys with origin {string} of client {int}") - public void show_journeys_with_origin_owned_by_client(String origin, int clientID) { - for (Container key : myContainers.keySet()) { - assertEquals(key.getOwner(), clientID); - assertEquals(myContainers.get(key).getOrigin(), origin); - } - } - - @Then("show journeys with destination {string} of client {int}") - public void show_journeys_with_destination_of_client(String destination, int clientID) { - for (Container key : myContainers.keySet()) { - assertEquals(key.getOwner(), clientID); - assertEquals(myContainers.get(key).getDestination(), destination); - } - } - - @Then("show journeys with content-type {string} of client {int}") - public void show_journeys_with_content_type_of_client(String contentType, int clientID) { - for (Container key : myContainers.keySet()) { - assertEquals(key.getOwner(), clientID); - assertEquals(key.getContentType(), contentType); - } - } - - @Then("show journeys with company {string} of client {int}") - public void show_journeys_with_company_of_client(String company, int clientID) { - for (Container key : myContainers.keySet()) { - assertEquals(key.getOwner(), clientID); - assertEquals(key.getCompany(), company); - } - } - - @Then("show all journeys of client {int}") - public void show_all_journeys_of_client(Integer int1) { - // Write code here that turns the phrase above into concrete actions - throw new io.cucumber.java.PendingException(); - } - -// -// @When("completing journey {string}") -// public void completing_journey(String journeyID) { -// response = manager.completeJourney(journeyID); -// -// } -// -// @Then("remove from record") -// public void remove_from_record() { -// assertEquals(record.getRecord().get("CO00001"), null); -// assertEquals(response.getErrorMessage(), "Journey has been completed and succesfully removed from the record"); -// assertEquals(response.getErrorCode(), 050); -// } -// -// @Then("deny removal") -// public void deny_removal() { -// assertEquals(response.getErrorMessage(), "Journey was not found"); -// assertEquals(response.getErrorCode(), 700); -// } -// - -} diff --git a/System/src/test/java/StepDefinitionRegisterClients.java b/System/src/test/java/StepDefinitionRegisterClients.java new file mode 100644 index 0000000..954bd62 --- /dev/null +++ b/System/src/test/java/StepDefinitionRegisterClients.java @@ -0,0 +1,177 @@ +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.LogisticsCompany; +import response.ResponseObject; + +import static org.junit.Assert.*; +import java.util.ArrayList; + +public class StepDefinitionRegisterClients { + + LogisticsCompany logisticsCompany = LogisticsCompany.getInstance(); + Client newClient = new Client(); + Client registeredClient = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + Client clientWithSameNameasRegisteredClient = new Client("Alice", "Allison", "999999","AliceAllison12@gmail.com" , "12345679"); + Client clientWithoutEmail; + Client clientWithoutPhoneNumber; + Client registeredClient2 = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + LogisticsCompany logisticscompany2; + Client unregisteredClient; + ArrayList theReturnedClientList; + ResponseObject response1; + ResponseObject response2; + + + //Scenario 1 A client is registering in the system with date of birth, full name and email, phone number + + + @Given("a new client with name {string}") + public void a_new_client_with_name(String name) { + + newClient.setfirstName("Alice"); + newClient.setlastName("Allison"); + + } + + @Given("born {string}") + public void born(String BirthDate) { + newClient.setBirthDate(BirthDate); + } + + @Given("with email {string}") + public void with_email(String email) { + newClient.setEmail(email); + } + + @Given("with phone number {string}") + public void with_phone_number(String PhoneNumber) { + newClient.setPhoneNumber(PhoneNumber); + } + + @When("the company registers the client") + public void the_company_registers_the_client() throws Exception { + + logisticsCompany.cleanDataBase(); + logisticsCompany.CreateNewClient(newClient); + + + } + @Then("the client is registered in the system successfully") + public void the_client_is_registered_in_the_system_successfully() { + + assertTrue(logisticsCompany.getClientDatabase().ClientExists(newClient)); + } + + @Then("the client is assigned a unique company ID {int}") + public void the_client_is_assigned_a_unique_company_ID(Integer id) { + assertTrue(logisticsCompany.getClientDatabase().checkID(newClient)); + + } + //Scenario 2 Same client registers again + @Given("a registered client") + public void a_registered_client() throws Exception { + logisticsCompany.cleanDataBase(); + response1 = logisticsCompany.CreateNewClient(registeredClient); + + + + } + + @When("the registered client tries to register again") + public void the_registered_client_tries_to_register_again() throws Exception { + response2 = logisticsCompany.CreateNewClient(registeredClient); + + } + + @Then("the client is not registered in the system again") + public void the_client_is_not_registered_in_the_system_again() { + assertTrue(response1.getErrorCode() == 1000); + assertTrue(response2.getErrorCode() == 1003); + + } + + //scenario 3 Two client with same name but different contact info register + + + @Given("an already registered client") + public void an_already_registered_client() throws Exception { + logisticsCompany.cleanDataBase(); + logisticsCompany.CreateNewClient(registeredClient); + } + + @When("a new client registers with the same name but different contact info") + public void a_new_client_registers_with_the_same_name_but_different_contact_info() throws Exception { + logisticsCompany.CreateNewClient(clientWithSameNameasRegisteredClient); + + } + + @Then("the new client is registered in the system successfully") + public void the_new_client_is_registered_in_the_system_successfully() { + logisticsCompany.getClientDatabase().ClientExists(registeredClient); + logisticsCompany.getClientDatabase().ClientExists(clientWithSameNameasRegisteredClient); + + } + + @Then("both clients have different unique company IDs") + public void both_clients_have_different_unique_company_IDs() { + assertTrue(logisticsCompany.getClientDatabase().checkID(registeredClient)); + assertTrue(logisticsCompany.getClientDatabase().checkID(clientWithSameNameasRegisteredClient)); + } + + //Scenario 4: Client tries to register without name + + @Given("a client without a name") + public void a_client_without_a_name() { + } + + @When("they try to regsiter without a name") + public void they_try_to_regsiter_without_a_name() throws Exception { + logisticsCompany.cleanDataBase(); + response1 = logisticsCompany.CreateNewClient(newClient); + } + + @Then("then the client is not registered in the system") + public void then_the_client_is_not_registered_in_the_system() { + assertTrue(response1.getErrorCode() == 1001); + } + //scenario 5: Client tries to register with one contact info + + @Given("a client with all info except email") + public void a_client_with_all_info_except_email() { + clientWithoutEmail = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + clientWithoutEmail.setEmail(null); + } + + @When("they try to regsiter without an email") + public void they_try_to_regsiter_without_an_email() throws Exception { + logisticsCompany.cleanDataBase(); + response1 = logisticsCompany.CreateNewClient(clientWithoutEmail); + } + + @Then("then the client is registered in the system successfully") + public void then_the_client_is_registered_in_the_system_successfully() { + assertTrue(response1.getErrorCode() == 1002); + } + //Scenario 6: Client tries to register with the other contact info + + @Given("a client with all info except phone number") + public void a_client_with_all_info_except_phone_number() { + clientWithoutPhoneNumber = new Client("Alice", "Allison","01012000" ,"AliceAllison@gmail.com", "12345678"); + clientWithoutPhoneNumber.setPhoneNumber(null); + } + + @When("they try to regsiter without an phone number") + public void they_try_to_regsiter_without_an_phone_number() throws Exception { + logisticsCompany.cleanDataBase(); + response1 = logisticsCompany.CreateNewClient(clientWithoutPhoneNumber); + + } + + @Then("then the client without the phone numver is registered in the system successfully") + public void then_the_client_without_the_phone_numver_is_registered_in_the_system_successfully() { + assertTrue(response1.getErrorCode() == 1002); + + } +} \ No newline at end of file diff --git a/System/src/test/java/StepDefinitonSharingInformation.java b/System/src/test/java/StepDefinitonSharingInformation.java new file mode 100644 index 0000000..03ac29b --- /dev/null +++ b/System/src/test/java/StepDefinitonSharingInformation.java @@ -0,0 +1,75 @@ +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import management.Client; +import management.LogisticsCompany; +import response.ResponseObject; + +import static org.junit.Assert.*; +import java.util.ArrayList; + +public class StepDefinitonSharingInformation { + + LogisticsCompany comp = LogisticsCompany.getInstance(); + Client friend1 = new Client("Alice", "Allison","01\01\2000" ,"AliceAllison@gmail.com", "12345678", "password"); + Client friend2 = new Client("bob", "bobinison", "11\02\2002","Bob@gmail.com" , "12345679"); + ResponseObject response1; + ResponseObject response2; + Client seenFriend ; + + //Scenario 1: Send your information to another client successfully + @Given("two registed clients2") + public void two_registed_clients2() throws Exception { + comp.cleanDataBase(); + comp.CreateNewClient(friend1); + comp.CreateNewClient(friend2); + + } + + @When("one client sends his information to the other client") + public void one_client_sends_his_information_to_the_other_client() { + response1 = friend1.addFriend("Bob@gmail.com", comp.getClientDatabase()); + } + + @Then("The information is successfully sent") + public void the_information_is_successfully_sent() { + assertTrue("information shared successfully", response1.getErrorCode()==11560); + } + //Scenario 2: Send your information to another client unsuccessfully + @Given("one registed client and his unregisted friend") + public void one_registed_client_and_his_unregisted_friend() throws Exception { + comp.CreateNewClient(friend1); + } + + @When("one client sends his information to the unregisted client") + public void one_client_sends_his_information_to_the_unregisted_client() { + response2 = friend1.addFriend("Bobthatdoesnotexist@gmail.com", comp.getClientDatabase()); + + + } + + @Then("The information is not successfully sent") + public void the_information_is_not_successfully_sent() { + assertTrue("information shared successfully", response2.getErrorCode()==11021); + } + + + //Scenario being able to access friend's shared information + @When("one client tries to access his friend's information") + public void one_client_tries_to_access_his_friend_s_information() { + friend2.updateFriendsList(1); + } + + @Then("The information received successfully.") + public void the_information_received_successfully() { + seenFriend = friend2.getMyFriends(comp.getClientDatabase()).get(0); + assertTrue("information shared successfully", seenFriend.getId() == friend1.getId()); + assertTrue("information shared successfully", seenFriend.getfirstName().equals(friend1.getfirstName())); + assertTrue("information shared successfully", seenFriend.getlastName().equals(friend1.getlastName())); + assertTrue("information shared successfully", seenFriend.getEmail().equals(friend1.getEmail())); + assertTrue("information shared successfully", seenFriend.getPhoneNumber().equals(friend1.getPhoneNumber())); + + + } + +} \ No newline at end of file diff --git a/System/target/classes/clientsManagement/Client.class b/System/target/classes/clientsManagement/Client.class deleted file mode 100644 index 552e204..0000000 Binary files a/System/target/classes/clientsManagement/Client.class and /dev/null differ diff --git a/System/target/classes/containerStatusTracking/Class.class b/System/target/classes/containerStatusTracking/Class.class deleted file mode 100644 index 9eaf155..0000000 Binary files a/System/target/classes/containerStatusTracking/Class.class and /dev/null differ diff --git a/System/target/classes/journeysManagement/Container.class b/System/target/classes/journeysManagement/Container.class deleted file mode 100644 index fb05e2c..0000000 Binary files a/System/target/classes/journeysManagement/Container.class and /dev/null differ diff --git a/System/target/classes/journeysManagement/ResponseObject.class b/System/target/classes/journeysManagement/ResponseObject.class deleted file mode 100644 index c4d1c02..0000000 Binary files a/System/target/classes/journeysManagement/ResponseObject.class and /dev/null differ diff --git a/System/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/System/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index cbe6d71..499e686 100644 --- a/System/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/System/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,14 +1,107 @@ -journeysManagement\JourneySerializer.class -containerStatusTracking\Class.class -journeysManagement\ContainerDatabase.class -journeysManagement\Container.class -journeysManagement\JourneyDeserializer.class -journeysManagement\Company.class -journeysManagement\HistoryBook.class -journeysManagement\ResponseObject.class -Testing.class -journeysManagement\Journey.class -journeysManagement\JourneyDatabase.class -JsonDatabase.class -clientsManagement\Client.class -clientsManagement\Registery.class +view\DisplayJourneysRegisterView$2.class +controller\ApplicationController.class +view\DisplayJourneysCompanyView$3.class +view\DisplayContainersView$2.class +controller\ClientPersonalInfoController.class +view\DisplayJourneysClientView$4.class +view\ClientPersonalInfoView$1.class +view\DisplayClientsView$3.class +view\IdFormatErrorGUI.class +view\DisplayContainersView$5.class +view\DisplayJourneyContainersClientView$3.class +controller\MainMenuCompanyController.class +view\DisplayJourneysRegisterView.class +view\DisplayJourneyContainersCompanyView$4.class +view\DateFormatErrorGUI.class +view\MainMenuCompanyView$5.class +view\DisplayJourneysClientView$1.class +view\AddHistoryView$1.class +management\HistoryBook.class +controller\DisplayJourneysRegisterController.class +view\MainMenuCompanyView$2.class +controller\MainMenuClientController.class +view\DisplayJourneysCompanyView$8.class +view\FriendsMainMenuView$1.class +management\LogisticsCompany.class +view\DisplayRegisterView$2.class +view\DisplayJourneyContainersClientView$4.class +view\HistoryView.class +controller\DisplayContainersController.class +view\AddHistoryView.class +controller\LoginController.class +view\DisplayJourneysCompanyView$1.class +management\JourneyDatabase.class +view\DisplayJourneyContainersClientView.class +view\DisplayContainersView$3.class +view\CompanyPersonalInfoView.class +view\ClientPersonalInfoView.class +view\DisplayContainersView.class +view\DisplayJourneysRegisterView$1.class +view\DisplayJourneysCompanyView$6.class +view\FriendsMainMenuView$3.class +view\DisplayJourneyContainersCompanyView.class +view\MainMenuClientView$4.class +view\MainMenuCompanyView$4.class +utils\GridBagLayoutUtils.class +controller\DisplayJourneyContainersClientController.class +view\MainMenuClientView.class +view\DisplayJourneyContainersCompanyView$3.class +view\DisplayJourneysCompanyView$10.class +view\DisplayJourneyContainersClientView$2.class +management\ClientDatabase.class +view\FriendsMainMenuView$2.class +controller\FriendsMainMenuController.class +controller\CompanyPersonalInfoController.class +view\DisplayJourneysCompanyView$7.class +controller\DisplayJourneysCompanyController.class +view\MainMenuCompanyView$3.class +view\DisplayJourneysClientView.class +view\MainMenuClientView$3.class +view\MainMenuCompanyView.class +controller\AddHistorycontroller.class +view\DisplayRegisterView$1.class +controller\DisplayJourneysClientController.class +controller\HistoryController.class +management\Container.class +view\DisplayJourneysCompanyView$2.class +serialization\JourneyDeserializer.class +management\Journey.class +management\Client.class +view\DisplayJourneysCompanyView.class +controller\SeeHistoryController.class +view\LoginView.class +serialization\JourneySerializer.class +view\DisplayContainersView$1.class +view\DisplayJourneysCompanyView$5.class +controller\User.class +view\DisplayClientsView$2.class +view\DisplayContainersView$4.class +view\ContainerErrorGUI.class +view\SeeHistoryView.class +view\MainMenuCompanyView$1.class +view\CompanyPersonalInfoView$1.class +view\DisplayJourneysClientView$2.class +view\DisplayJourneysRegisterView$4.class +view\DisplayContainersView$7.class +view\MainMenuClientView$2.class +controller\DisplayJourneyContainersCompanyController.class +controller\Session.class +view\DisplayClientsView.class +view\LoginView$1.class +view\FriendsMainMenuView.class +view\DisplayClientsView$1.class +controller\DisplayRegisterController.class +view\DisplayJourneyContainersCompanyView$1.class +view\DisplayJourneysRegisterView$3.class +view\DisplayJourneysCompanyView$9.class +view\DisplayJourneysCompanyView$4.class +view\SeeHistoryView$1.class +management\ContainerDatabase.class +view\MainMenuClientView$1.class +view\DisplayRegisterView.class +view\DisplayJourneyContainersClientView$1.class +view\DisplayContainersView$6.class +view\DisplayJourneysClientView$3.class +controller\DisplayClientsController.class +response\ResponseObject.class +view\DisplayJourneyContainersCompanyView$2.class diff --git a/System/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/System/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index f0b192d..bcfe546 100644 --- a/System/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/System/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,14 +1,52 @@ -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\Company.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\ContainerDatabase.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\Container.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\HistoryBook.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\JourneyDatabase.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\clientsManagement\Client.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\JourneyDeserializer.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\containerStatusTracking\Class.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\Journey.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\clientsManagement\Registery.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\ResponseObject.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\journeysManagement\JourneySerializer.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\JsonDatabase.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\main\java\Testing.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\HistoryView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\ContainerDatabase.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayJourneyContainersClientView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\AddHistorycontroller.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\IdFormatErrorGUI.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\HistoryBook.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\SeeHistoryView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayJourneysClientView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayContainersView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\SeeHistoryController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\CompanyPersonalInfoController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\MainMenuCompanyController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayJourneysRegisterView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\response\ResponseObject.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayClientsView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayClientsController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\AddHistoryView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayJourneysRegisterController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\Journey.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\HistoryController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\MainMenuClientController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\Client.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\ClientDatabase.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\MainMenuCompanyView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\ApplicationController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\LogisticsCompany.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\ContainerErrorGUI.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayJourneysCompanyView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayJourneysClientController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\LoginController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\Container.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\MainMenuClientView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayJourneyContainersClientController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\LoginView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\FriendsMainMenuController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayRegisterView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\ClientPersonalInfoController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\User.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DateFormatErrorGUI.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayJourneysCompanyController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\FriendsMainMenuView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayJourneyContainersCompanyController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\serialization\JourneySerializer.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayContainersController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\DisplayRegisterController.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\controller\Session.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\serialization\JourneyDeserializer.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\ClientPersonalInfoView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\CompanyPersonalInfoView.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\management\JourneyDatabase.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\utils\GridBagLayoutUtils.java +C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management-newBranch\System\src\main\java\view\DisplayJourneyContainersCompanyView.java diff --git a/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst deleted file mode 100644 index 50c618e..0000000 --- a/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ /dev/null @@ -1,3 +0,0 @@ -StepDefinitionM1.class -CucumberTest.class -StepDefinitionM2.class diff --git a/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index 5fd6873..0000000 --- a/System/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst +++ /dev/null @@ -1,3 +0,0 @@ -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\test\java\StepDefinitionM2.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\test\java\StepDefinitionM1.java -C:\Users\Alan\Desktop\02160 Agile Object-oriented Software Development\Remote-Container-Management\System\src\test\java\CucumberTest.java diff --git a/System/target/surefire-reports/CucumberTest.txt b/System/target/surefire-reports/CucumberTest.txt deleted file mode 100644 index 141b103..0000000 --- a/System/target/surefire-reports/CucumberTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: CucumberTest -------------------------------------------------------------------------------- -Tests run: 41, Failures: 0, Errors: 0, Skipped: 9, Time elapsed: 2.415 sec diff --git a/System/target/surefire-reports/TEST-CucumberTest.xml b/System/target/surefire-reports/TEST-CucumberTest.xml deleted file mode 100644 index 7fa175b..0000000 --- a/System/target/surefire-reports/TEST-CucumberTest.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/System/target/test-classes/CucumberTest.class b/System/target/test-classes/CucumberTest.class deleted file mode 100644 index 9912a99..0000000 Binary files a/System/target/test-classes/CucumberTest.class and /dev/null differ diff --git a/System/target/test-classes/StepDefinitionM2.class b/System/target/test-classes/StepDefinitionM2.class deleted file mode 100644 index ce7b2c1..0000000 Binary files a/System/target/test-classes/StepDefinitionM2.class and /dev/null differ