1515 */
1616package org .ehcache .management .providers .settings ;
1717
18- import com .fasterxml .jackson .annotation .JsonIgnore ;
19- import com .fasterxml .jackson .databind .ObjectMapper ;
2018import org .ehcache .CacheManager ;
2119import org .ehcache .config .CacheConfiguration ;
2220import org .ehcache .config .builders .CacheConfigurationBuilder ;
2927import org .ehcache .management .registry .DefaultManagementRegistryConfiguration ;
3028import org .ehcache .management .registry .DefaultSharedManagementService ;
3129import org .junit .After ;
32- import org .junit .Before ;
3330import org .junit .ClassRule ;
3431import org .junit .Test ;
3532import org .junit .rules .TemporaryFolder ;
3633import org .junit .runner .RunWith ;
3734import org .junit .runners .JUnit4 ;
35+ import org .terracotta .json .DefaultJsonFactory ;
36+ import org .terracotta .json .Json ;
37+ import org .terracotta .json .gson .GsonModule ;
3838import org .terracotta .management .model .capabilities .Capability ;
39- import org .terracotta .management .model .capabilities .context . CapabilityContext ;
39+ import org .terracotta .management .model .capabilities .descriptors . Descriptor ;
4040
41- import java .io .FileNotFoundException ;
4241import java .io .IOException ;
42+ import java .net .URISyntaxException ;
43+ import java .nio .charset .StandardCharsets ;
44+ import java .nio .file .Files ;
45+ import java .nio .file .Paths ;
4346import java .time .Duration ;
44- import java .util .Collection ;
45- import java .util .Scanner ;
4647
4748import static org .ehcache .config .builders .ResourcePoolsBuilder .newResourcePoolsBuilder ;
4849import static org .junit .Assert .assertEquals ;
@@ -55,12 +56,10 @@ public class EhcacheSettingsProviderTest {
5556
5657 CacheManager cacheManager ;
5758 SharedManagementService sharedManagementService = new DefaultSharedManagementService ();
58- ObjectMapper mapper = new ObjectMapper ();
59-
60- @ Before
61- public void before () {
62- mapper .addMixIn (CapabilityContext .class , CapabilityContextMixin .class );
63- }
59+ Json mapper = new DefaultJsonFactory ()
60+ .withModule ((GsonModule ) config -> config .serializeSubtypes (Descriptor .class ))
61+ .pretty ()
62+ .create ();
6463
6564 @ After
6665 public void after () {
@@ -70,7 +69,7 @@ public void after() {
7069 }
7170
7271 @ Test
73- public void test_standalone_ehcache () throws IOException {
72+ public void test_standalone_ehcache () throws IOException , URISyntaxException {
7473 CacheConfiguration <String , String > cacheConfiguration1 = CacheConfigurationBuilder .newCacheConfigurationBuilder (String .class , String .class ,
7574 newResourcePoolsBuilder ()
7675 .heap (10 , EntryUnit .ENTRIES )
@@ -103,12 +102,9 @@ public void test_standalone_ehcache() throws IOException {
103102
104103 cacheManager .init ();
105104
106- String expected = read ("/settings-capability.json" )
107- .replaceAll ("instance-id" , serviceConfiguration .getInstanceId ());
108- String actual = mapper .writeValueAsString (getSettingsCapability ())
109- .replaceAll ("\\ \" cacheManagerDescription\\ \" :\\ \" .*\\ \" ,\\ \" instanceId\\ \" " , "\\ \" cacheManagerDescription\\ \" :\\ \" \\ \" ,\\ \" instanceId\\ \" " )
110- .replaceAll ("\\ \" instanceId\\ \" :\\ \" .*\\ \" ,\\ \" managementContext\\ \" " , "\\ \" instanceId\\ \" :\\ \" UUID\\ \" ,\\ \" managementContext\\ \" " )
111- .replaceAll ("\\ \" instanceId\\ \" :\\ \" .*\\ \" ,\\ \" cacheManagerName\\ \" " , "\\ \" instanceId\\ \" :\\ \" UUID\\ \" ,\\ \" cacheManagerName\\ \" " );
105+ String expected = read ("/settings-capability.json" ).trim ();
106+ String actual = mapper .toString (getSettingsCapability ())
107+ .replaceAll ("\" instanceId\" : \" [0-9a-f-]+\" " , "\" instanceId\" : \" \" " );
112108
113109 // assertThat for formatted string comparison: ide support is bad
114110 assertEquals (expected , actual );
@@ -123,18 +119,8 @@ private Capability getSettingsCapability() {
123119 throw new AssertionError ();
124120 }
125121
126- private String read (String path ) throws FileNotFoundException {
127- try (Scanner scanner = new Scanner (getClass ().getResourceAsStream (path ), "UTF-8" )) {
128- return scanner .nextLine ();
129- }
122+ private String read (String resource ) throws IOException , URISyntaxException {
123+ return new String (Files .readAllBytes (Paths .get (getClass ().getResource (resource ).toURI ())), StandardCharsets .UTF_8 )
124+ .replaceAll ("\r " , "" );
130125 }
131-
132- public static abstract class CapabilityContextMixin {
133- @ JsonIgnore
134- public abstract Collection <String > getRequiredAttributeNames ();
135-
136- @ JsonIgnore
137- public abstract Collection <CapabilityContext .Attribute > getRequiredAttributes ();
138- }
139-
140126}
0 commit comments