Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions doc/legal_holds.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ for (BoxLegalHoldPolicy.Info policyInfo : policies) {
Create New Legal Hold Policy
----------------------------

The static [`create(BoxAPIConnection api, String name)`][create-new-legal-hold-policy]
method will let you create a new legal hold policy with a specified name. The
static
[`create(BoxAPIConnection api, String name, String description, Date startDate, Date endDate)`][create-new-legal-hold-policy-with-dates]
The static [`create(BoxAPIConnection api, String name, String description, Date startDate, Date endDate)`][create-new-legal-hold-policy-with-dates]
method will let you create a new legal hold policy with a specified name, description, start and end dates.

```java
BoxLegalHoldPolicy.Info policyInfo = BoxLegalHoldPolicy.create(api, name, description, startedAt, endedAt);
```

If you wish to create an ongoing Legal Hold Policy with no end date, call [`createOngoing(BoxAPIConnection api, String name, String description)`][create-ongoing].
If you wish to create an ongoing Legal Hold Policy with no end date and a description, call [`createOngoing(BoxAPIConnection api, String name, String description)`][create-ongoing].

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just document this version; they can always just pass null for the description.


```java
BoxLegalHoldPolicy.Info policyInfo = BoxLegalHoldPolicy.createOngoing(api, name, description);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/box/sdk/BoxLegalHoldPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Info getInfo(String ... fields) {
* @return information about the Legal Hold Policy created.
*/
public static BoxLegalHoldPolicy.Info create(BoxAPIConnection api, String name) {
return create(api, name, null, null, null);
return createOngoing(api, name, null);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/Fixtures/BoxLegalHold/PostLegalHoldPolicies201.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"created_at": "2018-04-25T16:37:05-07:00",
"modified_at": "2018-04-25T16:37:05-07:00",
"deleted_at": null,
"filter_started_at": null,
"filter_ended_at": null
"filter_started_at": "2018-04-25T16:37:05-07:00",
"filter_ended_at": "2020-04-25T16:37:05-07:00"
}
51 changes: 49 additions & 2 deletions src/test/java/com/box/sdk/BoxLegalHoldPolicyTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.box.sdk;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.IOException;
import java.util.Iterator;

Expand Down Expand Up @@ -90,10 +93,12 @@ public void testCreateNewLegalHoldPolicySucceedsAndSendsCorrectJson() throws IOE
final String createdByLogin = "testuser@example.com";
final String policyName = "Trial Documents";


JsonObject policyObject = new JsonObject()
.add("policy_name", policyName);
.add("policy_name", policyName)
.add("is_ongoing", true);

result = TestConfig.getFixture("BoxLegalHold/PostLegalHoldPolicies201");
result = TestConfig.getFixture("BoxLegalHold/PostOngoingLegalHoldPolicies201");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(legalHoldsURL))
.withRequestBody(WireMock.equalToJson(policyObject.toString()))
Expand All @@ -108,6 +113,48 @@ public void testCreateNewLegalHoldPolicySucceedsAndSendsCorrectJson() throws IOE
Assert.assertEquals(createdByName, policyInfo.getCreatedBy().getName());
Assert.assertEquals(createdByLogin, policyInfo.getCreatedBy().getLogin());
Assert.assertEquals(policyName, policyInfo.getPolicyName());
Assert.assertTrue(policyInfo.getIsOngoing());
}

@Test
@Category(UnitTest.class)
public void testCreateNewLegalHoldPolicyWithDateFilters() throws IOException, ParseException {
String result = "";
final String legalHoldsURL = "/legal_hold_policies";
final String policyID = "11111";
final String createdByID = "33333";
final String createdByName = "Test User";
final String createdByLogin = "testuser@example.com";
final String policyName = "Trial Documents";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
final String startTimeString = "2018-04-25T23:37:05+0000";
final String endTimeString = "2020-04-25T23:37:05+0000";
final Date startTime = dateFormat.parse("2018-04-25T16:37:05-07:00");
final Date endTime = dateFormat.parse("2020-04-25T16:37:05-07:00");

JsonObject policyObject = new JsonObject()
.add("policy_name", policyName)
.add("filter_started_at", startTimeString)
.add("filter_ended_at", endTimeString);

result = TestConfig.getFixture("BoxLegalHold/PostLegalHoldPolicies201");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(legalHoldsURL))
.withRequestBody(WireMock.equalToJson(policyObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withBody(result)));

BoxLegalHoldPolicy.Info policyInfo = BoxLegalHoldPolicy.create(this.api, policyName, null,
startTime, endTime);

Assert.assertEquals(policyID, policyInfo.getID());
Assert.assertEquals(createdByID, policyInfo.getCreatedBy().getID());
Assert.assertEquals(createdByName, policyInfo.getCreatedBy().getName());
Assert.assertEquals(createdByLogin, policyInfo.getCreatedBy().getLogin());
Assert.assertEquals(policyName, policyInfo.getPolicyName());
Assert.assertEquals(startTime, policyInfo.getFilterStartedAt());
Assert.assertEquals(endTime, policyInfo.getFilterEndedAt());
}

@Test
Expand Down