SDN Controller Programming Guide
124
equals2, unequal);
}
@Test
public void testSerialization() {
Switch device = //... create with attributes set to non-null values
SerializabilityTester.testSerialization(device);
}
}
BeanTest utility class—A rudimentary facility for generic testing of basic bean getter and setter
functionality. It uses reflection to locate matching getter/setter pairs in the supplied bean instance.
EqualityTester class—Verifies the equivalence relation on non-null object references as
documented in the Java Object.equals(Object) method; it follows the equals contract and makes
sure its properties hold: reflexive, symmetric, transitive, consistent and non-null reference.
SerializabilityTester class—Serializes and deserializes the object being tested looking for
serialization failures (java.io.NotSerializableException) which are thrown when an instance is
required to have a Serializable interface. It is crucial to set a non-null value to all non-transient
attributes in the object under test, otherwise serialization failures won’t be detected.
Creating Domain Service (Business Logic)
The following information defines a service to provide Open Flow Switches functionality (The
sample application’s business logic). This service basically provides operations to create, read,
update and delete open flow switches (CRUD operations).
Service API
Service API abstracts the business logic implementation by defining an API that clients or
consumers use in order to interact with Open Flow switches. This API will act as the Open Flow
Switch service contract. The following listing shows the Open Flow Switch service API which should
be created under hm-api module.
SwitchService.java (Sample Application Service API):
package com.hp.hm.api;
import com.hp.api.Id;
import com.hp.hm.model.Switch;
import com.hp.hm.model.SwitchFilter;
import com.hp.hm.model.SwitchSortKey;
import com.hp.util.SortSpecification;
...
public interface SwitchService {
public Switch add(Switch device);
public void update(Switch device);