-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDP-5826-filling the kit history from files #187
Open
pegahtah
wants to merge
7
commits into
develop
Choose a base branch
from
DDP-5826
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0fd2997
Tool for migrating kits from file to db
pegahtah 8781ebd
TestUnit for Testing that tool
pegahtah a1de833
Added fix for when one line has less kits that the other one
pegahtah 47b33b7
Added more tests
pegahtah 1cf3d00
Added more logging
pegahtah 981d74a
Merge remote-tracking branch 'origin/develop' into HEAD
pegahtah d1ab551
Added more logging
pegahtah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
src/test/java/org/broadinstitute/dsm/UPSKitToolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
package org.broadinstitute.dsm; | ||
|
||
import org.broadinstitute.dsm.db.DDPInstance; | ||
import org.broadinstitute.dsm.util.DBTestUtil; | ||
import org.broadinstitute.dsm.util.model.Kit; | ||
import org.broadinstitute.dsm.util.tools.TbosUPSKitTool; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
import static org.broadinstitute.dsm.TestHelper.setupDB; | ||
import static org.broadinstitute.dsm.util.tools.TbosUPSKitTool.readFile; | ||
|
||
public class UPSKitToolTest { | ||
@Test | ||
public void testDateConversion() { | ||
String dateTimeStringInUTC = "2020-12-16T14:46:51Z"; | ||
String dateTimeStringInEST = TbosUPSKitTool.getSQLDateTimeString(dateTimeStringInUTC); | ||
Assert.assertEquals(dateTimeStringInEST, "2020-12-16 09:46:51"); | ||
} | ||
|
||
@Test | ||
public void testKitSetValue() { | ||
Kit kit = new Kit(); | ||
kit.setValueByHeader("kit label", "aaa"); | ||
Assert.assertEquals(kit.getKitLabel(), "aaa"); | ||
kit.setValueByHeader("reason", null); | ||
Assert.assertEquals(kit.getReason(), null); | ||
kit.setValueByHeader("result", "result1"); | ||
Assert.assertEquals(kit.getResult(), "result1"); | ||
kit.setValueByHeader("requested at", "2020-09-18T13:54:14.159Z"); | ||
Assert.assertEquals(kit.getRequestedAt(), "2020-09-18T13:54:14.159Z"); | ||
kit.setValueByHeader("shipped at", "2020-09-18T11:54:14.159Z"); | ||
Assert.assertEquals(kit.getShippedAt(), "2020-09-18T11:54:14.159Z"); | ||
kit.setValueByHeader("delivered at", "2020-09-15T11:54:14.159Z"); | ||
Assert.assertEquals(kit.getDeliveredAt(), "2020-09-15T11:54:14.159Z"); | ||
kit.setValueByHeader("picked up at", "2020-08-15T11:54:14.159Z"); | ||
Assert.assertEquals(kit.getPickedUpAt(), "2020-08-15T11:54:14.159Z"); | ||
kit.setValueByHeader("received at", "2020-08-15T12:54:14.159Z"); | ||
Assert.assertEquals(kit.getReceivedAt(), "2020-08-15T12:54:14.159Z"); | ||
kit.setValueByHeader("resulted at", "2019-08-15T12:54:14.159Z"); | ||
Assert.assertEquals(kit.getResultedAt(), "2019-08-15T12:54:14.159Z"); | ||
} | ||
|
||
@Test | ||
public void testReadFile() { | ||
// String fileContent = TestUtil.readFile("NdiTestFile.txt"); | ||
Map<String, ArrayList<Kit>> participants = readFile("src/test/resources/TbosUPSKitToolTestFile.csv"); | ||
Assert.assertNotNull(participants); | ||
Assert.assertEquals(participants.size(), 1); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PMVYGB")); | ||
Assert.assertEquals(participants.get("TestBoston_PMVYGB").size(), 1); | ||
ArrayList<Kit> ptKits = participants.get("TestBoston_PMVYGB"); | ||
Assert.assertEquals(ptKits.size(), 1); | ||
Kit kit = ptKits.get(0); | ||
Assert.assertEquals(kit.getKitLabel(), "TBOS-test"); | ||
Assert.assertNull(kit.getReason()); | ||
Assert.assertNull(kit.getResult()); | ||
} | ||
|
||
@Test | ||
public void testReadFileMultiPt() { | ||
Map<String, ArrayList<Kit>> participants = readFile("src/test/resources/TbosUPSKitToolMultiPtKits.csv"); | ||
Assert.assertNotNull(participants); | ||
Assert.assertEquals(participants.size(), 2); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PMVYGB")); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PBPD68")); | ||
Assert.assertEquals(participants.get("TestBoston_PMVYGB").size(), 1); | ||
Assert.assertEquals(participants.get("TestBoston_PBPD68").size(), 2); | ||
ArrayList<Kit> ptKits = participants.get("TestBoston_PMVYGB"); | ||
Assert.assertEquals(ptKits.size(), 1); | ||
Kit kit = ptKits.get(0); | ||
Assert.assertEquals(kit.getKitLabel(), "TBOS-test"); | ||
Assert.assertNull(kit.getReason()); | ||
Assert.assertNull(kit.getResult()); | ||
ptKits = participants.get("TestBoston_PBPD68"); | ||
Assert.assertEquals(ptKits.size(), 2); | ||
kit = ptKits.get(0); | ||
Assert.assertEquals(kit.getKitLabel(), "TBOS-test4"); | ||
Assert.assertEquals(kit.getRequestedAt(), "2020-09-19T01:57:49Z"); | ||
Assert.assertNull(kit.getReason()); | ||
Assert.assertNull(kit.getResult()); | ||
kit = ptKits.get(1); | ||
Assert.assertEquals(kit.getKitLabel(), "TBOS-test6"); | ||
Assert.assertEquals(kit.getRequestedAt(), "2020-09-22T10:57:49Z"); | ||
Assert.assertNull(kit.getReason()); | ||
Assert.assertNull(kit.getResult()); | ||
} | ||
|
||
|
||
@Test | ||
public void testGetDDPKitBasedOnKitLabel() { | ||
DDPInstance ddpInstance = DDPInstance.getDDPInstance("testboston"); | ||
Kit outboundKit = TbosUPSKitTool.getDDBKitBasedOnKitLabel(TbosUPSKitTool.SQL_SELECT_KIT_BY_KIT_LABEL + TbosUPSKitTool.SQL_SELECT_OUTBOUND, "TBOS-test", ddpInstance.getDdpInstanceId()); | ||
Assert.assertNotNull(outboundKit); | ||
Map<String, ArrayList<Kit>> participants = readFile("src/test/resources/TbosUPSKitToolTestFile.csv"); | ||
Assert.assertNotNull(participants); | ||
Assert.assertEquals(participants.size(), 1); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PMVYGB")); | ||
Assert.assertEquals(participants.get("TestBoston_PMVYGB").size(), 1); | ||
ArrayList<Kit> ptKits = participants.get("TestBoston_PMVYGB"); | ||
Assert.assertEquals(ptKits.get(0).getGuid(), outboundKit.getGuid()); | ||
Assert.assertEquals(ptKits.get(0).getShortId(), outboundKit.getShortId()); | ||
Assert.assertEquals(ptKits.get(0).getKitLabel(), outboundKit.getKitLabel()); | ||
Assert.assertEquals("1Z9YA775YW21328147", outboundKit.getTrackingToId()); | ||
Assert.assertEquals("2309", outboundKit.getDsmKitRequestId()); | ||
|
||
Kit inboundKit = TbosUPSKitTool.getDDBKitBasedOnKitLabel(TbosUPSKitTool.SQL_SELECT_KIT_BY_KIT_LABEL + TbosUPSKitTool.SQL_SELECT_INBOUND, "TBOS-test", ddpInstance.getDdpInstanceId()); | ||
Assert.assertNotNull(inboundKit); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PMVYGB")); | ||
Assert.assertEquals(participants.get("TestBoston_PMVYGB").size(), 1); | ||
Assert.assertEquals(ptKits.get(0).getGuid(), inboundKit.getGuid()); | ||
Assert.assertEquals(ptKits.get(0).getShortId(), inboundKit.getShortId()); | ||
Assert.assertEquals(ptKits.get(0).getKitLabel(), inboundKit.getKitLabel()); | ||
Assert.assertEquals("92748902118533553033028108", inboundKit.getTrackingReturnId()); | ||
Assert.assertEquals("2309", outboundKit.getDsmKitRequestId()); | ||
} | ||
|
||
@Test | ||
public void testInsertShipment() { | ||
Map<String, ArrayList<Kit>> participants = readFile("src/test/resources/TbosUPSKitToolMultiPtKits.csv"); | ||
Assert.assertNotNull(participants); | ||
Assert.assertEquals(participants.size(), 2); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PMVYGB")); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PBPD68")); | ||
Assert.assertEquals(participants.get("TestBoston_PMVYGB").size(), 1); | ||
Assert.assertEquals(participants.get("TestBoston_PBPD68").size(), 2); | ||
ArrayList<Kit> ptKits = participants.get("TestBoston_PMVYGB"); | ||
Assert.assertEquals(ptKits.size(), 1); | ||
Kit kit = ptKits.get(0); | ||
DDPInstance ddpInstance = DDPInstance.getDDPInstance("testboston"); | ||
Kit outboundKit = TbosUPSKitTool.getDDBKitBasedOnKitLabel(TbosUPSKitTool.SQL_SELECT_KIT_BY_KIT_LABEL + TbosUPSKitTool.SQL_SELECT_OUTBOUND, "TBOS-test", ddpInstance.getDdpInstanceId()); | ||
Assert.assertNotNull(outboundKit); | ||
kit.setDsmKitRequestId(outboundKit.getDsmKitRequestId()); | ||
kit.setTrackingToId(outboundKit.getTrackingToId()); | ||
kit.setTrackingReturnId(outboundKit.getTrackingReturnId()); | ||
kit.setShipmentId(outboundKit.getShipmentId()); | ||
kit.setPackageId(outboundKit.getPackageId()); | ||
String shipmentId = TbosUPSKitTool.insertShipmentForKit(kit.getDsmKitRequestId()); | ||
kit.setShipmentId(shipmentId); | ||
Assert.assertNotNull(shipmentId); | ||
TbosUPSKitTool.insertPackagesForKit(kit); | ||
String outboundPackage = TbosUPSKitTool.getPackageIdForKit(kit, false); | ||
String inboundPackage = TbosUPSKitTool.getPackageIdForKit(kit, true); | ||
Assert.assertNotNull(outboundPackage); | ||
Assert.assertNotNull(inboundPackage); | ||
Assert.assertNotEquals(inboundPackage, outboundPackage); | ||
DBTestUtil.deleteFromQuery(shipmentId, "delete from ups_package where ups_shipment_id = ?"); | ||
DBTestUtil.deleteFromQuery(shipmentId, "delete from ups_shipment where ups_shipment_id = ?"); | ||
} | ||
|
||
@Test | ||
public void testTheBeforeFunction() { | ||
Map<String, ArrayList<Kit>> participants = readFile("src/test/resources/TbosUPSKitToolMultiPtKits.csv"); | ||
Assert.assertNotNull(participants); | ||
Assert.assertEquals(participants.size(), 2); | ||
Assert.assertTrue(participants.keySet().contains("TestBoston_PBPD68")); | ||
Assert.assertEquals(participants.get("TestBoston_PBPD68").size(), 2); | ||
ArrayList<Kit> ptKits = participants.get("TestBoston_PBPD68"); | ||
Assert.assertEquals(ptKits.size(), 2); | ||
Kit kit = ptKits.get(1); | ||
DDPInstance ddpInstance = DDPInstance.getDDPInstance("testboston"); | ||
Kit dbKit = TbosUPSKitTool.getDDBKitBasedOnKitLabel(TbosUPSKitTool.SQL_SELECT_KIT_BY_KIT_LABEL + TbosUPSKitTool.SQL_SELECT_OUTBOUND, kit.getKitLabel(), ddpInstance.getDdpInstanceId()); | ||
Assert.assertEquals( "2021-04-22 14:22:00", dbKit.getLastActivityDateTime()); | ||
Assert.assertEquals( "2021-04-19T21:38:31Z", kit.getShippedAt()); | ||
boolean b = TbosUPSKitTool.shouldInsertBasedOnTimeForKit(dbKit, kit.getShippedAt()); | ||
Assert.assertFalse(b); | ||
} | ||
|
||
|
||
@BeforeClass | ||
public static void first() { | ||
setupDB(); | ||
} | ||
|
||
@Ignore | ||
@Test | ||
public void InsertFile() { | ||
Map<String, ArrayList<Kit>> participants = TbosUPSKitTool.readFile("src/test/resources/TbosUPSKitToolTestFile.csv"); | ||
TbosUPSKitTool.insertFileInfo(participants); | ||
} | ||
|
||
|
||
} |
117 changes: 117 additions & 0 deletions
117
src/test/java/org/broadinstitute/dsm/util/model/Kit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.broadinstitute.dsm.util.model; | ||
SimoneMaiwald marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import lombok.Data; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@Data | ||
public class Kit { | ||
|
||
String kitLabel; | ||
String reason; | ||
String result; | ||
String requestedAt; | ||
String shippedAt; | ||
String deliveredAt; | ||
String pickedUpAt; | ||
String receivedAt; | ||
String resultedAt; | ||
String dsmKitRequestId; | ||
String trackingToId; | ||
String trackingReturnId; | ||
String lastActivityDateTime; | ||
String lastActivityDesc; | ||
String shipmentId; | ||
String packageId; | ||
String shortId; | ||
String guid; | ||
|
||
public Kit() { | ||
} | ||
|
||
public Kit(String kitLabel, | ||
String reason, | ||
String result, | ||
String requestedAt, | ||
String shippedAt, | ||
String deliveredAt, | ||
String pickedUpAt, | ||
String receivedAt, | ||
String resultedAt, | ||
String dsmKitRequestId, | ||
String trackingToId, | ||
String trackingReturnId, | ||
String lastActivityDateTime, | ||
String lastActivityDesc, | ||
String shipmentId, | ||
String packageId, | ||
String shortId, | ||
String guid) { | ||
this.kitLabel = kitLabel; | ||
this.reason = reason; | ||
this.result = result; | ||
this.requestedAt = requestedAt; | ||
this.shippedAt = shippedAt; | ||
this.deliveredAt = deliveredAt; | ||
this.pickedUpAt = pickedUpAt; | ||
this.receivedAt = receivedAt; | ||
this.resultedAt = resultedAt; | ||
this.dsmKitRequestId = dsmKitRequestId; | ||
this.trackingToId = trackingToId; | ||
this.trackingReturnId = trackingReturnId; | ||
this.lastActivityDateTime = lastActivityDateTime; | ||
this.lastActivityDesc = lastActivityDesc; | ||
this.shipmentId = shipmentId; | ||
this.packageId = packageId; | ||
this.shortId = shortId; | ||
this.guid = guid; | ||
} | ||
|
||
public void setValueByHeader(String header, String value) { | ||
switch (header) { | ||
case "kit label": | ||
this.kitLabel = value; | ||
break; | ||
case "reason": | ||
this.reason = value; | ||
break; | ||
case "result": | ||
this.result = value; | ||
break; | ||
case "requested at": | ||
this.requestedAt = value; | ||
break; | ||
case "shipped at": | ||
this.shippedAt = value; | ||
break; | ||
case "delivered at": | ||
this.deliveredAt = value; | ||
break; | ||
case "picked up at": | ||
this.pickedUpAt = value; | ||
break; | ||
case "received at": | ||
this.receivedAt = value; | ||
break; | ||
case "resulted at": | ||
this.resultedAt = value; | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected header, value: " + header + "," + value); | ||
} | ||
} | ||
|
||
public boolean isEmpty() { | ||
if (StringUtils.isBlank(kitLabel) && | ||
StringUtils.isBlank(reason) && | ||
StringUtils.isBlank(result) && | ||
StringUtils.isBlank(requestedAt) && | ||
StringUtils.isBlank(shippedAt) && | ||
StringUtils.isBlank(deliveredAt) && | ||
StringUtils.isBlank(pickedUpAt) && | ||
StringUtils.isBlank(receivedAt) && | ||
StringUtils.isBlank(resultedAt)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this class to test the methods I made in the migatioonTool