mirror of
https://github.com/google/nomulus.git
synced 2025-08-05 01:11:50 +02:00
Replace command.applyTo() with inlined builder operations
These are much easier to understand. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=137446273
This commit is contained in:
parent
b84d7f1fb5
commit
1dbc5f6bb0
28 changed files with 489 additions and 426 deletions
|
@ -24,14 +24,14 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.flows.ResourceFlowTestCase;
|
||||
import google.registry.flows.ResourceFlowUtils.AddRemoveSameValueException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
|
||||
import google.registry.flows.ResourceFlowUtils.StatusNotClientSettableException;
|
||||
import google.registry.flows.contact.ContactFlowUtils.BadInternationalizedPostalInfoException;
|
||||
import google.registry.flows.contact.ContactFlowUtils.DeclineContactDisclosureFieldDisallowedPolicyException;
|
||||
import google.registry.flows.exceptions.AddRemoveSameValueEppException;
|
||||
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
||||
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
|
||||
import google.registry.flows.exceptions.StatusNotClientSettableException;
|
||||
import google.registry.model.contact.ContactAddress;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.contact.PostalInfo;
|
||||
|
@ -84,7 +84,7 @@ public class ContactUpdateFlowTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_updatingOnePostalInfoDeletesTheOther() throws Exception {
|
||||
public void testSuccess_updatingInternationalizedPostalInfoDeletesLocalized() throws Exception {
|
||||
ContactResource contact =
|
||||
persistResource(
|
||||
newContactResource(getUniqueIdFromCommand()).asBuilder()
|
||||
|
@ -104,12 +104,60 @@ public class ContactUpdateFlowTest
|
|||
// the localized one since they are treated as a pair for update purposes.
|
||||
assertAboutContacts().that(contact)
|
||||
.hasNonNullLocalizedPostalInfo().and()
|
||||
.hasInternationalizedPostalInfo(null);
|
||||
.hasNullInternationalizedPostalInfo();
|
||||
|
||||
runFlowAssertResponse(readFile("contact_update_response.xml"));
|
||||
assertAboutContacts().that(reloadResourceByForeignKey())
|
||||
.hasLocalizedPostalInfo(null).and()
|
||||
.hasNonNullInternationalizedPostalInfo();
|
||||
.hasNullLocalizedPostalInfo().and()
|
||||
.hasInternationalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.INTERNATIONALIZED)
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("124 Example Dr.", "Suite 200"))
|
||||
.setCity("Dulles")
|
||||
.setState("VA")
|
||||
.setZip("20166-6503")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_updatingLocalizedPostalInfoDeletesInternationalized() throws Exception {
|
||||
setEppInput("contact_update_localized.xml");
|
||||
ContactResource contact =
|
||||
persistResource(
|
||||
newContactResource(getUniqueIdFromCommand()).asBuilder()
|
||||
.setInternationalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.INTERNATIONALIZED)
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("111 8th Ave", "4th Floor"))
|
||||
.setCity("New York")
|
||||
.setState("NY")
|
||||
.setZip("10011")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build())
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
// The test xml updates the localized postal info and should therefore implicitly delete
|
||||
// the internationalized one since they are treated as a pair for update purposes.
|
||||
assertAboutContacts().that(contact)
|
||||
.hasNonNullInternationalizedPostalInfo().and()
|
||||
.hasNullLocalizedPostalInfo();
|
||||
|
||||
runFlowAssertResponse(readFile("contact_update_response.xml"));
|
||||
assertAboutContacts().that(reloadResourceByForeignKey())
|
||||
.hasNullInternationalizedPostalInfo().and()
|
||||
.hasLocalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.LOCALIZED)
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("124 Example Dr.", "Suite 200"))
|
||||
.setCity("Dulles")
|
||||
.setState("VA")
|
||||
.setZip("20166-6503")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -148,6 +196,73 @@ public class ContactUpdateFlowTest
|
|||
.build());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSuccess_updateOnePostalInfo_touchOtherPostalInfoPreservesIt() throws Exception {
|
||||
setEppInput("contact_update_partial_postalinfo_preserve_int.xml");
|
||||
persistResource(
|
||||
newContactResource(getUniqueIdFromCommand()).asBuilder()
|
||||
.setLocalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.LOCALIZED)
|
||||
.setName("A. Person")
|
||||
.setOrg("Company Inc.")
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("123 4th st", "5th Floor"))
|
||||
.setCity("City")
|
||||
.setState("AB")
|
||||
.setZip("12345")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build())
|
||||
.setInternationalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.INTERNATIONALIZED)
|
||||
.setName("B. Person")
|
||||
.setOrg("Company Co.")
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("100 200th Dr.", "6th Floor"))
|
||||
.setCity("Town")
|
||||
.setState("CD")
|
||||
.setZip("67890")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build())
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
// The test xml updates the address of the localized postal info. It also sets the name of the
|
||||
// internationalized postal info to the same value it previously had, which causes it to be
|
||||
// preserved. If the xml had not mentioned the internationalized one at all it would have been
|
||||
// deleted.
|
||||
runFlowAssertResponse(readFile("contact_update_response.xml"));
|
||||
assertAboutContacts().that(reloadResourceByForeignKey())
|
||||
.hasLocalizedPostalInfo(
|
||||
new PostalInfo.Builder()
|
||||
.setType(Type.LOCALIZED)
|
||||
.setName("A. Person")
|
||||
.setOrg("Company Inc.")
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("456 5th st"))
|
||||
.setCity("Place")
|
||||
.setState("CD")
|
||||
.setZip("54321")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build())
|
||||
.and()
|
||||
.hasInternationalizedPostalInfo(
|
||||
new PostalInfo.Builder()
|
||||
.setType(Type.INTERNATIONALIZED)
|
||||
.setName("B. Person")
|
||||
.setOrg("Company Co.")
|
||||
.setAddress(new ContactAddress.Builder()
|
||||
.setStreet(ImmutableList.of("100 200th Dr.", "6th Floor"))
|
||||
.setCity("Town")
|
||||
.setState("CD")
|
||||
.setZip("67890")
|
||||
.setCountryCode("US")
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_neverExisted() throws Exception {
|
||||
thrown.expect(
|
||||
|
@ -264,7 +379,7 @@ public class ContactUpdateFlowTest
|
|||
public void testFailure_addRemoveSameValue() throws Exception {
|
||||
setEppInput("contact_update_add_remove_same.xml");
|
||||
persistActiveContact(getUniqueIdFromCommand());
|
||||
thrown.expect(AddRemoveSameValueEppException.class);
|
||||
thrown.expect(AddRemoveSameValueException.class);
|
||||
runFlow();
|
||||
}
|
||||
}
|
||||
|
|
36
javatests/google/registry/flows/contact/testdata/contact_update_localized.xml
vendored
Normal file
36
javatests/google/registry/flows/contact/testdata/contact_update_localized.xml
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<update>
|
||||
<contact:update
|
||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:add>
|
||||
<contact:status s="clientDeleteProhibited"/>
|
||||
</contact:add>
|
||||
<contact:chg>
|
||||
<contact:postalInfo type="loc">
|
||||
<contact:org/>
|
||||
<contact:addr>
|
||||
<contact:street>124 Example Dr.</contact:street>
|
||||
<contact:street>Suite 200</contact:street>
|
||||
<contact:city>Dulles</contact:city>
|
||||
<contact:sp>VA</contact:sp>
|
||||
<contact:pc>20166-6503</contact:pc>
|
||||
<contact:cc>US</contact:cc>
|
||||
</contact:addr>
|
||||
</contact:postalInfo>
|
||||
<contact:voice>+1.7034444444</contact:voice>
|
||||
<contact:fax/>
|
||||
<contact:authInfo>
|
||||
<contact:pw>2fooBAR</contact:pw>
|
||||
</contact:authInfo>
|
||||
<contact:disclose flag="1">
|
||||
<contact:voice/>
|
||||
<contact:email/>
|
||||
</contact:disclose>
|
||||
</contact:chg>
|
||||
</contact:update>
|
||||
</update>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -0,0 +1,25 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<update>
|
||||
<contact:update
|
||||
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
|
||||
<contact:id>sh8013</contact:id>
|
||||
<contact:chg>
|
||||
<contact:postalInfo type="loc">
|
||||
<contact:addr>
|
||||
<contact:street>456 5th st</contact:street>
|
||||
<contact:city>Place</contact:city>
|
||||
<contact:sp>CD</contact:sp>
|
||||
<contact:pc>54321</contact:pc>
|
||||
<contact:cc>US</contact:cc>
|
||||
</contact:addr>
|
||||
</contact:postalInfo>
|
||||
<contact:postalInfo type="int">
|
||||
<contact:org>Company Co.</contact:org>
|
||||
</contact:postalInfo>
|
||||
</contact:chg>
|
||||
</contact:update>
|
||||
</update>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
Loading…
Add table
Add a link
Reference in a new issue