Skip to content
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

add change type to delete batch input #69

Merged
merged 3 commits into from
May 16, 2019
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
53 changes: 11 additions & 42 deletions src/main/java/io/vinyldns/java/model/batch/AddChangeInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,16 @@
import io.vinyldns.java.model.record.data.RecordData;
import java.util.Objects;

public class AddChangeInput implements ChangeInput {
private String inputName;

private RecordType type;

private Long ttl;

private RecordData record;

private ChangeInputType changeType = ChangeInputType.Add;
public class AddChangeInput extends ChangeInput {
private final Long ttl;
private final RecordData record;

public AddChangeInput(String inputName, RecordType type, Long ttl, RecordData record) {
this.inputName = inputName;
this.type = type;
super(ChangeInputType.Add, inputName, type);
this.ttl = ttl;
this.record = record;
}

@Override
public ChangeInputType getChangeType() {
return changeType;
}

@Override
public String getInputName() {
return inputName;
}

public RecordType getType() {
return type;
}

public Long getTtl() {
return ttl;
}
Expand All @@ -59,32 +37,23 @@ public RecordData getRecord() {

@Override
public String toString() {
return "AddChangeInput{"
+ "inputName='"
+ inputName
+ '\''
+ ", type="
+ type
+ ", ttl="
+ ttl
+ ", record="
+ record
+ '}';
return String.format(
"AddChangeInput{changeType='%s', inputName='%s', type='%s', ttl='%s', record='%s'}",
this.getChangeType(), this.getInputName(), this.getType(), this.ttl, this.record);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AddChangeInput that = (AddChangeInput) o;
return Objects.equals(inputName, that.inputName)
&& type == that.type
&& Objects.equals(ttl, that.ttl)
&& Objects.equals(record, that.record);
return super.equals(o)
&& Objects.equals(this.ttl, that.ttl)
&& Objects.equals(this.record, that.record);
}

@Override
public int hashCode() {
return Objects.hash(inputName, type, ttl, record);
return super.hashCode() + Objects.hash(ttl, record);
}
}
41 changes: 38 additions & 3 deletions src/main/java/io/vinyldns/java/model/batch/ChangeInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,44 @@
*/
package io.vinyldns.java.model.batch;

public interface ChangeInput {
import io.vinyldns.java.model.record.RecordType;
import java.util.Objects;

ChangeInputType getChangeType();
public class ChangeInput {
private final ChangeInputType changeType;
private final String inputName;
private final RecordType type;

String getInputName();
public ChangeInput(ChangeInputType changeType, String inputName, RecordType type) {
this.changeType = changeType;
this.inputName = inputName;
this.type = type;
}

public ChangeInputType getChangeType() {
return changeType;
}

public String getInputName() {
return inputName;
}

public RecordType getType() {
return type;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChangeInput that = (ChangeInput) o;
return this.inputName.equals(that.inputName)
&& this.changeType == that.changeType
&& this.type == that.type;
}

@Override
public int hashCode() {
return Objects.hash(inputName, changeType, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,17 @@
*/
package io.vinyldns.java.model.batch;

import java.util.Objects;
import io.vinyldns.java.model.record.RecordType;

public class DeleteRecordSetChangeInput implements ChangeInput {
private String inputName;

public DeleteRecordSetChangeInput(String inputName) {
this.inputName = inputName;
}

@Override
public ChangeInputType getChangeType() {
return ChangeInputType.DeleteRecordSet;
}

@Override
public String getInputName() {
return inputName;
public class DeleteRecordSetChangeInput extends ChangeInput {
public DeleteRecordSetChangeInput(String inputName, RecordType type) {
super(ChangeInputType.DeleteRecordSet, inputName, type);
}

@Override
public String toString() {
return "DeleteRecordSetChangeInput{" + "inputName='" + inputName + '\'' + '}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeleteRecordSetChangeInput that = (DeleteRecordSetChangeInput) o;
return Objects.equals(inputName, that.inputName);
}

@Override
public int hashCode() {

return Objects.hash(inputName);
return String.format(
"DeleteRecordSetChangeInput{changeType='%s', inputName='%s', type='%s'}",
this.getChangeType().name(), this.getInputName(), this.getType().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int getStatusCode() {

@Override
public String toString() {
return "value=" + value + ", statusCode=" + statusCode;
return "value=" + value + ", messageBody=" + messageBody + ", statusCode=" + statusCode;
}

@Override
Expand Down
49 changes: 33 additions & 16 deletions src/test/java/io/vinyldns/java/VinylDNSClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1066,27 +1066,44 @@ public void createBatchChangeSuccess() {

List<ChangeInput> changes = new ArrayList<>();
AData adata = new AData("1.2.3.4");
AddChangeInput input = new AddChangeInput("www.example.com", RecordType.A, 300L, adata);
changes.add(input);
AddChangeInput addInput = new AddChangeInput("www.example.com", RecordType.A, 300L, adata);
DeleteRecordSetChangeInput deleteInput =
new DeleteRecordSetChangeInput("www.example.com", RecordType.A);
changes.add(addInput);
changes.add(deleteInput);

CreateBatchRequest batchRequest = new CreateBatchRequest(changes);

AddSingleChange singleChange = new AddSingleChange();
singleChange.setChangeType(ChangeInputType.Add);
singleChange.setId("1234");
singleChange.setInputName("testString");
singleChange.setRecord(adata);
singleChange.setRecordChangeId("1111");
singleChange.setRecordName("testName");
singleChange.setRecordSetId("testId");
singleChange.setZoneId("testZone");
singleChange.setZoneName("testZoneName");
singleChange.setType(RecordType.A);
singleChange.setSystemMessage("testMessage");
singleChange.setStatus(SingleChangeStatus.Complete);
AddSingleChange addSingleChange = new AddSingleChange();
addSingleChange.setChangeType(ChangeInputType.Add);
addSingleChange.setId("1234");
addSingleChange.setInputName("testString");
addSingleChange.setRecord(adata);
addSingleChange.setRecordChangeId("1111");
addSingleChange.setRecordName("testName");
addSingleChange.setRecordSetId("testId");
addSingleChange.setZoneId("testZone");
addSingleChange.setZoneName("testZoneName");
addSingleChange.setType(RecordType.A);
addSingleChange.setSystemMessage("testMessage");
addSingleChange.setStatus(SingleChangeStatus.Complete);

DeleteRecordSetSingleChange deleteSingleChange = new DeleteRecordSetSingleChange();
deleteSingleChange.setChangeType(ChangeInputType.DeleteRecordSet);
deleteSingleChange.setId("1234");
deleteSingleChange.setInputName("testString");
deleteSingleChange.setRecordChangeId("1111");
deleteSingleChange.setRecordName("testName");
deleteSingleChange.setRecordSetId("testId");
deleteSingleChange.setZoneId("testZone");
deleteSingleChange.setZoneName("testZoneName");
deleteSingleChange.setTyp(RecordType.A);
deleteSingleChange.setSystemMessage("testMessage");
deleteSingleChange.setStatus(SingleChangeStatus.Complete);

List<SingleChange> singleChangeList = new ArrayList<>();
singleChangeList.add(singleChange);
singleChangeList.add(addSingleChange);
singleChangeList.add(deleteSingleChange);

BatchResponse batchResponse = new BatchResponse();
batchResponse.setId("1234");
Expand Down