use of com.company.demo.entity.Customer in project documentation by cuba-platform.
the class CustomerChangedListener method beforePersist.
@EventListener
void beforePersist(EntityPersistingEvent<Customer> event) {
Customer customer = event.getEntity();
customer.setCode(obtainNewCustomerCode(customer));
}
use of com.company.demo.entity.Customer in project documentation by cuba-platform.
the class CustomerChangedListener method beforeCommit.
// <1>
@EventListener
public void beforeCommit(EntityChangedEvent<Customer, UUID> event) {
// <2>
Id<Customer, UUID> entityId = event.getEntityId();
// <3>
EntityChangedEvent.Type changeType = event.getType();
AttributeChanges changes = event.getChanges();
if (changes.isChanged("name")) {
// <4>
// <5>
String oldName = changes.getOldValue("name");
// ...
}
}
use of com.company.demo.entity.Customer in project documentation by cuba-platform.
the class CustomerTest method testCreateLoadRemove.
@Test
void testCreateLoadRemove() {
Customer customer = cont.metadata().create(Customer.class);
customer.setName("c1");
Customer committedCustomer = dataManager.commit(customer);
assertEquals(customer, committedCustomer);
Customer loadedCustomer = dataManager.load(Id.of(customer)).one();
assertEquals(customer, loadedCustomer);
dataManager.remove(loadedCustomer);
}
use of com.company.demo.entity.Customer in project documentation by cuba-platform.
the class CustomerEditLoadDataTest method setUp.
@BeforeEach
public void setUp() throws Exception {
new Expectations() {
{
// <2>
dataService.load((LoadContext<? extends Entity>) any);
result = new Delegate() {
Entity load(LoadContext lc) {
if ("demo_Customer".equals(lc.getEntityMetaClass())) {
return customer;
} else
return null;
}
};
}
};
// <3>
TestServiceProxy.mock(DataService.class, dataService);
TestEntityFactory<Customer> customersFactory = environment.getContainer().getEntityFactory(Customer.class, TestEntityState.DETACHED);
customer = customersFactory.create("name", "Homer", "email", // <4>
"homer@simpson.com");
}
Aggregations