-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pz2
committed
Jul 15, 2024
1 parent
7f8fe14
commit 21a397b
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
changelog/unreleased/000001-sorting_connections_tabel_by_type.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: Sorting connections tabel by type | ||
authors: | ||
- name: Peter Zmilczak | ||
nick: marwin1991 | ||
url: https://github.com/marwin1991 | ||
type: changed #[added/changed/deprecated/removed/fixed/security/other] | ||
merge_requests: | ||
- 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
hofund-core/src/test/java/dev/logchange/hofund/connection/HofundConnectionsTableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dev.logchange.hofund.connection; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class HofundConnectionsTableTest { | ||
|
||
@Test | ||
void testSortByType() { | ||
// given: | ||
TastableHofundConnectionsProvider provider = new TastableHofundConnectionsProvider(); | ||
HofundConnectionsTable table = new HofundConnectionsTable(Collections.singletonList(provider)); | ||
String expected = | ||
"+----------+---------+--------+------+\n" + | ||
"| TYPE | NAME | STATUS | URL |\n" + | ||
"+----------+---------+--------+------+\n" + | ||
"| HTTP | target1 | UP | fake |\n" + | ||
"| HTTP | target3 | UP | fake |\n" + | ||
"| DATABASE | target2 | UP | fake |\n" + | ||
"| DATABASE | target4 | UP | fake |\n" + | ||
"+----------+---------+--------+------+\n"; | ||
|
||
// when: | ||
String result = table.print(); | ||
|
||
// then: | ||
assertEquals(expected, result); | ||
} | ||
|
||
private static class TastableHofundConnectionsProvider implements HofundConnectionsProvider { | ||
|
||
public List<HofundConnection> getConnections() { | ||
return Arrays.asList( | ||
getHofundConnection("target1", Type.HTTP), | ||
getHofundConnection("target2", Type.DATABASE), | ||
getHofundConnection("target3", Type.HTTP), | ||
getHofundConnection("target4", Type.DATABASE) | ||
); | ||
} | ||
|
||
} | ||
|
||
private static HofundConnection getHofundConnection(String target, Type type) { | ||
return new HofundConnection( | ||
target, | ||
"fake", | ||
type, | ||
new AtomicReference<>(() -> Status.UP) | ||
); | ||
} | ||
} |