Search in sources :

Example 1 with GeoLocation

use of example.GeoLocation in project elide by yahoo.

the class PersistentResourceTest method testUpdateComplexAttributeAllNullFieldsNested.

@Test
public void testUpdateComplexAttributeAllNullFieldsNested() {
    Company company = newCompany("abc");
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Company> parentResource = new PersistentResource<>(company, "1", goodScope);
    final Address address = new Address();
    address.setStreet1(null);
    address.setStreet2(null);
    final GeoLocation geo = new GeoLocation();
    geo.setLatitude("lat");
    geo.setLongitude("long");
    address.setGeo(geo);
    parentResource.updateAttribute("address", address);
    assertEquals(address, company.getAddress(), "The attribute was updated successfully");
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(company, goodScope);
}
Also used : Company(example.Company) Address(example.Address) GeoLocation(example.GeoLocation) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Example 2 with GeoLocation

use of example.GeoLocation in project elide by yahoo.

the class PersistentResourceTest method testUpdateComplexAttributeNestedAllNullFields.

@Test
public void testUpdateComplexAttributeNestedAllNullFields() {
    Company company = newCompany("abc");
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Company> parentResource = new PersistentResource<>(company, "1", goodScope);
    final Address address = new Address();
    address.setStreet1("street1");
    address.setStreet2("street2");
    final GeoLocation geo = new GeoLocation();
    geo.setLatitude(null);
    geo.setLongitude(null);
    address.setGeo(geo);
    parentResource.updateAttribute("address", address);
    assertEquals(address, company.getAddress(), "The attribute was updated successfully");
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(company, goodScope);
}
Also used : Company(example.Company) Address(example.Address) GeoLocation(example.GeoLocation) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Example 3 with GeoLocation

use of example.GeoLocation in project elide by yahoo.

the class PersistentResourceTest method testUpdateComplexAttributeNestedNullField.

@Test
public void testUpdateComplexAttributeNestedNullField() {
    Company company = newCompany("abc");
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Company> parentResource = new PersistentResource<>(company, "1", goodScope);
    final Address address = new Address();
    address.setStreet1("street1");
    address.setStreet2("street2");
    final GeoLocation geo = new GeoLocation();
    geo.setLatitude(null);
    geo.setLongitude("long");
    address.setGeo(geo);
    parentResource.updateAttribute("address", address);
    assertEquals(address, company.getAddress(), "The attribute was updated successfully");
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(company, goodScope);
}
Also used : Company(example.Company) Address(example.Address) GeoLocation(example.GeoLocation) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Example 4 with GeoLocation

use of example.GeoLocation in project elide by yahoo.

the class PersistentResourceTest method testUpdateComplexAttributeNested.

@Test
public void testUpdateComplexAttributeNested() {
    Company company = newCompany("abc");
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Company> parentResource = new PersistentResource<>(company, "1", goodScope);
    final Address address = new Address();
    address.setStreet1("street1");
    address.setStreet2("street2");
    final GeoLocation geo = new GeoLocation();
    geo.setLatitude("lat");
    geo.setLongitude("long");
    address.setGeo(geo);
    parentResource.updateAttribute("address", address);
    assertEquals(address, company.getAddress(), "The attribute was updated successfully");
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(company, goodScope);
}
Also used : Company(example.Company) Address(example.Address) GeoLocation(example.GeoLocation) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Example 5 with GeoLocation

use of example.GeoLocation in project elide by yahoo.

the class PersistentResourceTest method testUpdateNestedComplexAttributeClone.

@Test
public void testUpdateNestedComplexAttributeClone() {
    Company company = newCompany("abc");
    Address originalAddress = new Address();
    originalAddress.setStreet1("street1");
    originalAddress.setStreet2("street2");
    GeoLocation originalGeo = new GeoLocation();
    originalGeo.setLatitude("1");
    originalGeo.setLongitude("2");
    originalAddress.setGeo(originalGeo);
    Map<String, Object> newAddress = new HashMap<>();
    newAddress.put("street1", "Elm");
    newAddress.put("street2", "Maple");
    Map<String, Object> newGeo = new HashMap<>();
    newGeo.put("latitude", "X");
    newGeo.put("longitude", "Y");
    newAddress.put("geo", newGeo);
    RequestScope goodScope = buildRequestScope(tx, goodUser);
    PersistentResource<Company> parentResource = new PersistentResource<>(company, "1", goodScope);
    parentResource.updateAttribute("address", newAddress);
    // check that original value was unmodified.
    assertEquals("street1", originalAddress.getStreet1());
    assertEquals("street2", originalAddress.getStreet2());
    assertEquals("1", originalAddress.getGeo().getLatitude());
    assertEquals("2", originalAddress.getGeo().getLongitude());
    // check the new value matches the expected.
    assertEquals("Elm", company.getAddress().getStreet1());
    assertEquals("Maple", company.getAddress().getStreet2());
    assertEquals("X", company.getAddress().getGeo().getLatitude());
    assertEquals("Y", company.getAddress().getGeo().getLongitude());
    goodScope.saveOrCreateObjects();
    verify(tx, times(1)).save(company, goodScope);
}
Also used : Company(example.Company) Address(example.Address) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) GeoLocation(example.GeoLocation) PatchRequestScope(com.yahoo.elide.jsonapi.extensions.PatchRequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)6 Address (example.Address)6 Company (example.Company)6 GeoLocation (example.GeoLocation)6 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1