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

The following examples show how to use org.springframework.hateoas.PagedResources#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: AppRegistryCommandsTests.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
@Test
public void importFromLocalResource() {
	String name1 = "foo";
	String type1 = "source";
	String uri1 = "file:///foo";
	String name2 = "bar";
	String type2 = "sink";
	String uri2 = "file:///bar";
	Properties apps = new Properties();
	apps.setProperty(type1 + "." + name1, uri1);
	apps.setProperty(type2 + "." + name2, uri2);
	List<AppRegistrationResource> resources = new ArrayList<>();
	resources.add(new AppRegistrationResource(name1, type1, uri1));
	resources.add(new AppRegistrationResource(name2, type2, uri2));
	PagedResources<AppRegistrationResource> pagedResources = new PagedResources<>(resources,
			new PagedResources.PageMetadata(resources.size(), 1, resources.size(), 1));
	when(appRegistryOperations.registerAll(apps, true)).thenReturn(pagedResources);
	String appsFileUri = "classpath:appRegistryCommandsTests-apps.properties";
	String result = appRegistryCommands.importFromResource(appsFileUri, true, true);
	assertEquals("Successfully registered applications: [source.foo, sink.bar]", result);
}
 
Example 2
Source File: RuntimeCommandsTests.java    From spring-cloud-dashboard 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);
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppStatusResource> result = new PagedResources<>(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 3
Source File: RuntimeCommandsTests.java    From spring-cloud-dashboard 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);
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppStatusResource> result = new PagedResources<>(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 4
Source File: CustomSearchController.java    From galeb with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@GetMapping(value = "/environment/findAllByVirtualhostgroupId", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PagedResources<Resource<Environment>>> findAllByVirtualhostgroupId(@RequestParam("vhgid") Long vhgid) {
    List<Environment> environments = environmentRepository.findAllByVirtualhostgroupId(vhgid);
    List<Resource<Environment>> resources = environments.stream().map(Resource::new).collect(Collectors.toList());
    PagedResources.PageMetadata meta = new PagedResources.PageMetadata(environments.size(), 0, environments.size());
    return ResponseEntity.ok(new PagedResources<>(resources, meta, Collections.emptyList()));
}
 
Example 5
Source File: AppRegistryCommandsTests.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Test
public void testHintOnEmptyList() {
	Collection<AppRegistrationResource> data = new ArrayList<>();
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppRegistrationResource> result = new PagedResources<>(data, metadata);
	when(appRegistryOperations.list()).thenReturn(result);

	Object commandResult = appRegistryCommands.list();
	assertThat((String) commandResult, CoreMatchers.containsString("app register"));
	assertThat((String) commandResult, CoreMatchers.containsString("app import"));
}
 
Example 6
Source File: AppRegistryCommandsTests.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Test
public void testList() {

	String[][] apps = new String[][] {
			{"http", "source"},
			{"filter", "processor"},
			{"transform", "processor"},
			{"file", "source"},
			{"log", "sink"},
			{"moving-average", "processor"}
	};

	Collection<AppRegistrationResource> data = new ArrayList<>();
	for (String[] app : apps) {
		data.add(new AppRegistrationResource(app[0], app[1], null));
	}
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppRegistrationResource> result = new PagedResources<>(data, metadata);
	when(appRegistryOperations.list()).thenReturn(result);

	Object[][] expected = new String[][] {
			{ "source", "processor", "sink" },
			{ "http", "filter", "log" },
			{ "file", "transform", null },
			{ null, "moving-average", null }
	};
	TableModel model = ((Table) appRegistryCommands.list()).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(model.getValue(row, col), Matchers.is(expected[row][col]));
		}
	}
}
 
Example 7
Source File: AppRegistryCommandsTests.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Test
public void importFromResource() {
	List<AppRegistrationResource> resources = new ArrayList<>();
	resources.add(new AppRegistrationResource("foo", "source", null));
	resources.add(new AppRegistrationResource("bar", "sink", null));
	PagedResources<AppRegistrationResource> pagedResources = new PagedResources<>(resources,
			new PagedResources.PageMetadata(resources.size(), 1, resources.size(), 1));
	String uri = "test://example";
	when(appRegistryOperations.importFromResource(uri, true)).thenReturn(pagedResources);
	String result = appRegistryCommands.importFromResource(uri, false, true);
	assertEquals("Successfully registered 2 applications from 'test://example'", result);
}
 
Example 8
Source File: RuntimeCommandsTests.java    From spring-cloud-dashboard with Apache License 2.0 5 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);
	PagedResources.PageMetadata metadata1 = new PagedResources.PageMetadata(instanceStatusResources1.size(), 1, instanceStatusResources1.size(), 1);
	PagedResources<AppInstanceStatusResource> resources = new PagedResources<>(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);
	PagedResources.PageMetadata metadata3 = new PagedResources.PageMetadata(instanceStatusResources2.size(), 1, instanceStatusResources2.size(), 1);
	PagedResources<AppInstanceStatusResource> resources2 = new PagedResources<>(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);
	PagedResources.PageMetadata metadata4 = new PagedResources.PageMetadata(instanceStatusResources3.size(), 1, instanceStatusResources3.size(), 1);
	PagedResources<AppInstanceStatusResource> resources3 = new PagedResources<>(instanceStatusResources3, metadata4);
	appStatusResource3.setInstances(resources3);
}