Java Code Examples for org.springframework.hateoas.PagedModel#PageMetadata

The following examples show how to use org.springframework.hateoas.PagedModel#PageMetadata . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuntimeCommandsTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testStatusWithSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	data.add(appStatusResource3);
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1);
	PagedModel<AppStatusResource> result = new PagedModel<>(data, metadata);
	when(runtimeOperations.status()).thenReturn(result);
	Object[][] expected = new String[][] { { "1", "deployed", "2" }, { "2", "undeployed", "0" },
			{ "3", "failed", "0" } };
	TableModel model = runtimeCommands.list(true, null).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col]));
		}
	}
}
 
Example 2
Source File: RuntimeCommandsTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testStatusWithoutSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1);
	PagedModel<AppStatusResource> result = new PagedModel<>(data, metadata);
	when(runtimeOperations.status()).thenReturn(result);
	Object[][] expected = new String[][] { { "1", "deployed", "2" }, { "10", "deployed" }, { "20", "deployed" },
			{ "2", "undeployed", "0" } };
	TableModel model = runtimeCommands.list(false, null).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col]));
		}
	}
}
 
Example 3
Source File: FeignHalController.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@GetMapping("/paged")
public CollectionModel<MarsRover> getPaged() {
	MarsRover marsRover = new MarsRover();
	marsRover.setName("Curiosity");
	Link link = new Link("/paged", "self");
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
	return new PagedModel<>(Collections.singleton(marsRover), metadata, link);
}
 
Example 4
Source File: RuntimeCommandsTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);
	when(dataFlowOperations.runtimeOperations()).thenReturn(runtimeOperations);
	DataFlowShell dataFlowShell = new DataFlowShell();
	dataFlowShell.setDataFlowOperations(dataFlowOperations);
	this.runtimeCommands = new RuntimeCommands(dataFlowShell);
	appStatusResource1 = new AppStatusResource("1", "deployed");
	Map<String, String> properties = new HashMap<>();
	properties.put("key1", "value1");
	properties.put("key2", "value1");
	AppInstanceStatusResource instanceStatusResource1 = new AppInstanceStatusResource("10", "deployed", properties);
	AppInstanceStatusResource instanceStatusResource2 = new AppInstanceStatusResource("20", "deployed", null);
	List<AppInstanceStatusResource> instanceStatusResources1 = new ArrayList<>();
	instanceStatusResources1.add(instanceStatusResource1);
	instanceStatusResources1.add(instanceStatusResource2);
	PagedModel.PageMetadata metadata1 = new PagedModel.PageMetadata(instanceStatusResources1.size(), 1,
			instanceStatusResources1.size(), 1);
	PagedModel<AppInstanceStatusResource> resources = new PagedModel<>(instanceStatusResources1, metadata1);
	appStatusResource1.setInstances(resources);
	appStatusResource2 = new AppStatusResource("2", "undeployed");
	AppInstanceStatusResource instanceStatusResource3 = new AppInstanceStatusResource("30", "undeployed", null);
	AppInstanceStatusResource instanceStatusResource4 = new AppInstanceStatusResource("40", "undeployed", null);
	List<AppInstanceStatusResource> instanceStatusResources2 = new ArrayList<>();
	instanceStatusResources1.add(instanceStatusResource3);
	instanceStatusResources1.add(instanceStatusResource4);
	PagedModel.PageMetadata metadata3 = new PagedModel.PageMetadata(instanceStatusResources2.size(), 1,
			instanceStatusResources2.size(), 1);
	PagedModel<AppInstanceStatusResource> resources2 = new PagedModel<>(instanceStatusResources2,
			metadata3);
	appStatusResource2.setInstances(resources2);
	appStatusResource3 = new AppStatusResource("3", "failed");
	AppInstanceStatusResource instanceStatusResource5 = new AppInstanceStatusResource("50", "failed", null);
	AppInstanceStatusResource instanceStatusResource6 = new AppInstanceStatusResource("60", "deployed", null);
	List<AppInstanceStatusResource> instanceStatusResources3 = new ArrayList<>();
	instanceStatusResources1.add(instanceStatusResource5);
	instanceStatusResources1.add(instanceStatusResource6);
	PagedModel.PageMetadata metadata4 = new PagedModel.PageMetadata(instanceStatusResources3.size(), 1,
			instanceStatusResources3.size(), 1);
	PagedModel<AppInstanceStatusResource> resources3 = new PagedModel<>(instanceStatusResources3,
			metadata4);
	appStatusResource3.setInstances(resources3);
}