-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding DateRangeContainerResource for filter by date usecase (#947)
- Loading branch information
1 parent
d5c4479
commit 584415f
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
...src/main/java/org/datatransferproject/types/common/models/DateRangeContainerResource.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,57 @@ | ||
/* | ||
* Copyright 2019 The Data Transfer Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.datatransferproject.types.common.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import java.util.Objects; | ||
|
||
/** A date range container containing start and end date for filtering. */ | ||
@JsonTypeName("org.dataportability:DateRangeContainerResource") | ||
public class DateRangeContainerResource extends ContainerResource { | ||
private final Integer startDate; | ||
private final Integer endDate; | ||
|
||
@JsonCreator | ||
public DateRangeContainerResource( | ||
@JsonProperty("startDate") Integer startDate, | ||
@JsonProperty("endDate") Integer endDate) { | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
|
||
public Integer getStartDate() { | ||
return startDate; | ||
} | ||
public Integer getEndDate() { return endDate; } | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
DateRangeContainerResource that = (DateRangeContainerResource) o; | ||
return Objects.equals(startDate, that.startDate) | ||
&& Objects.equals(endDate, that.endDate); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(startDate, endDate); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...test/java/org/datatransferproject/types/common/models/DateRangeContainerResourceTest.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,46 @@ | ||
/* | ||
* Copyright 2019 The Data Transfer Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.datatransferproject.types.common.models; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.truth.Truth; | ||
import org.junit.Test; | ||
|
||
public class DateRangeContainerResourceTest { | ||
@Test | ||
public void verifySerializeDeserialize() throws Exception { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerSubtypes(DateRangeContainerResource.class); | ||
|
||
int startDate = 1607784466; | ||
int endDate = 1608648466; | ||
|
||
ContainerResource data = new DateRangeContainerResource(startDate, endDate); | ||
|
||
String serialized = objectMapper.writeValueAsString(data); | ||
|
||
ContainerResource deserializedModel = | ||
objectMapper.readValue(serialized, ContainerResource.class); | ||
|
||
Truth.assertThat(deserializedModel).isNotNull(); | ||
Truth.assertThat(deserializedModel).isInstanceOf(DateRangeContainerResource.class); | ||
DateRangeContainerResource deserialized = (DateRangeContainerResource) deserializedModel; | ||
Truth.assertThat(deserialized.getStartDate()).isEqualTo(startDate); | ||
Truth.assertThat(deserialized.getEndDate()).isEqualTo(endDate); | ||
Truth.assertThat(deserialized).isEqualTo(data); | ||
} | ||
} |