use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.
the class PhotonModelUtils method updateEndpointLinks.
public static <T extends ServiceDocument> T updateEndpointLinks(T state, String endpointLink) {
if (state == null) {
return state;
}
ServiceDocumentDescription sdDesc = ServiceDocumentDescription.Builder.create().buildDescription(state.getClass());
// This method will assign the value of the endpointLinks if it does not exist for the given
// resource OR it will merge it with the existing collection if already set.
Set<String> endpointLinks = new HashSet<>();
endpointLinks.add(endpointLink);
ReflectionUtils.setOrUpdatePropertyValue(sdDesc.propertyDescriptions.get(PhotonModelConstants.FIELD_NAME_ENDPOINT_LINKS), state, endpointLinks);
return state;
}
use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.
the class ResourceUtilsTest method testOperationPatchNoChanges.
@Test
public void testOperationPatchNoChanges() {
ResourceState current = new ResourceState();
current.tenantLinks = new ArrayList<>(Arrays.asList("tenant1", "tenant2"));
current.groupLinks = new HashSet<>(Arrays.asList("groupA", "groupB"));
current.tagLinks = new HashSet<>(Arrays.asList("tag1", "tag2"));
ResourceState patch = new ResourceState();
Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, "/resource")).setBody(patch);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create().buildDescription(ResourceState.class);
ResourceUtils.handlePatch(null, patchOperation, current, desc, ResourceState.class, null);
assertTrue(patchOperation.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED));
}
use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.
the class ResourceUtilsTest method handlePatch.
private <T extends ResourceState> Operation handlePatch(T currentState, T patchState, Class<T> type) {
Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, "/resource")).setBody(patchState);
ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create().buildDescription(type);
ResourceUtils.handlePatch(null, patchOperation, currentState, desc, type, null);
return patchOperation;
}
Aggregations